示例#1
0
        void btnExport_Click(object sender, EventArgs e)
        {
            if (chkExportSystemProgress.Checked)
            {
                if (!DeveloperInfoTools.ExportDataGridView(dgvSystems, txtFolder.Text, txtSystemProgress.Text))
                {
                    return;
                }
            }

            if (chkExportDatasetProgress.Checked)
            {
                if (!DeveloperInfoTools.ExportDataGridView(dgvDatasets, txtFolder.Text, txtDatasetProgress.Text))
                {
                    return;
                }
            }

            if (chkExportCombinations.Checked)
            {
                if (!DeveloperInfoTools.ExportDataGridView(dgvCombinations, txtFolder.Text, txtCombinations.Text))
                {
                    return;
                }
            }

            UserInfoHandler.ShowInfo("Exporting files accomplished.");
        }
示例#2
0
        void SetAllDatasetsTo(string value)
        {
            try
            {
                int systemColumn = GetHitColumn();

                if (systemColumn == -1)
                {
                    UserInfoHandler.ShowInfo("Please open the menu via a position within the respective system's column.");
                    return;
                }

                foreach (DataGridViewRow row in dgvSwitches.Rows)
                {
                    if (row.Cells[systemColumn].ReadOnly == false)
                    {
                        row.Cells[systemColumn].Value = value;
                    }
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
 void VariablesForm_KeyUp(object sender, KeyEventArgs keyEventArgs)
 {
     if (keyEventArgs.Control && keyEventArgs.KeyCode == Keys.S)
     {
         if (_isReadOnly)
         {
             UserInfoHandler.ShowInfo("File is in read-only mode.");
         }
         else
         {
             SaveChanges();
         }
     }
     if (keyEventArgs.Control && keyEventArgs.KeyCode == Keys.Z)
     {
         PerformAction(new VariablesUndoAction(_undoManager));
     }
     if (keyEventArgs.Control && keyEventArgs.KeyCode == Keys.Y)
     {
         PerformAction(new VariablesRedoAction(_undoManager));
     }
     if (treeAcronyms.Focused == true)
     {
         _acronymManager.HandleEnterKey(keyEventArgs);
     }
 }
示例#4
0
        void SetAllSystemsTo(string value)
        {
            try
            {
                int datasetRow = GetHitRow();
                if (datasetRow == -1)
                {
                    UserInfoHandler.ShowInfo("Please open the menu via a position within the respective dataset's row.");
                    return;
                }

                DataGridViewRow row = dgvSwitches.Rows[datasetRow];
                foreach (DataGridViewColumn column in dgvSwitches.Columns)
                {
                    if (row.Cells[column.Index].ReadOnly == false)
                    {
                        row.Cells[column.Index].Value = value;
                    }
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
示例#5
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();
        }
示例#6
0
        void btnValidate_Click(object sender, EventArgs e)
        {
            validationItems = new List <string>(); countries = new List <string>();
            foreach (string validationItem in lstValidationItems.CheckedItems)
            {
                validationItems.Add(validationItem);
            }
            if (validationItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select at least one validation item."); return;
            }
            foreach (string country in lstCountries.CheckedItems)
            {
                countries.Add(country);
            }
            if (countries.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select at least one country."); return;
            }

            selectedFunction = PERFORM_VALIDATION;
            showProblemsOnly = chkShowProblemsOnly.Checked;
            DialogResult     = System.Windows.Forms.DialogResult.OK;
            Close(); // it is important to close this modal dialog otherwise it gets parent of the non-modal dialog showing validation results
                     // with the consequence that the non-modality of the result-dialog would be useless, as this modal dialog does not
                     // allow accessing the UI and if it's closed the non-modal dialog is closed too
                     // explicitly making the main-form parent of the non-modal dialog does not work either, because for whatever reason
                     // one cannot close the main-form anymore once the validation result dialog was started
        }
        bool handleServerConfiguration(out string userName, out string password, out string organizationID)
        {
            bool proceedLogin = true;

            userName = string.Empty; password = string.Empty;  organizationID = string.Empty;
            string serverURL = string.Empty; string serverName = string.Empty; string organisation = string.Empty; string author = string.Empty;
            string encryptKey = string.Empty; string encryptedUserName = string.Empty; string encryptedPassword = string.Empty;

            getServerConfiguration(out serverURL, out serverName, out organisation, out author, out encryptKey, out encryptedUserName, out encryptedPassword, out organizationID);

            if (string.IsNullOrEmpty(serverURL) || string.IsNullOrEmpty(organisation) || string.IsNullOrEmpty(author) || string.IsNullOrEmpty(encryptKey))
            {
                proceedLogin = false;
                UserInfoHandler.ShowInfo("You need to select a server from the 'VC settings' menu before proceeding.");

                VCSettings   vcSettingsDialog = new VCSettings();
                DialogResult result           = vcSettingsDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    proceedLogin = true;
                    getServerConfiguration(out serverURL, out serverName, out organisation, out author, out encryptKey, out encryptedUserName, out encryptedPassword, out organizationID);
                }
            }

            if (proceedLogin)
            {
                _vcAdministrator.setServerConfiguration(serverURL, serverName, organisation, encryptKey, author, encryptedUserName, out userName, encryptedPassword, out password);
            }

            return(proceedLogin);
        }
示例#8
0
        void cmbDatasets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDatasets.SelectedIndex == -1)
            {
                return; //no dataset selected
            }
            dgvFactors.Rows.Clear();

            //look up which dataset was selected to assess the data's income year, and put it into text-edit
            foreach (DataConfig.DataBaseRow dataset in _dataConfigFacade.GetDataBaseRows())
            {
                if (cmbDatasets.Text == dataset.Name)
                {
                    txtIncomeYear.Text = dataset.YearInc;
                    break;
                }
            }

            //check if the 'Raw Indices' table contains the data-year
            bool noIncomeYear = false;

            if (!GetExistingYears().Contains(txtIncomeYear.Text))
            {
                //UserInfoHandler.ShowError("Year " + txtIncomeYear.Text + " is not recorded in Raw Indices table. Factors cannot be calculated.");
                UserInfoHandler.ShowInfo("Year " + txtIncomeYear.Text + " is not recorded in Raw Indices table. Factors are set to " + _factorValueInvalid + ".");
                noIncomeYear = true;
                //return;
            }

            //fill the 'Factors ...' table for the selected dataset
            foreach (string indexName in GetIndicesNames()) //loop over all indices
            {
                //add one row to the 'Factors ...' table for each index
                DataGridViewRow factorRow = dgvFactors.Rows[dgvFactors.Rows.Add()];

                //put the name of the index (e.g. cpi) in the first column
                factorRow.Cells[colIndexName.Name].Value = indexName;

                foreach (DataGridViewColumn systemColumn in dgvFactors.Columns) //loop over the country's systems
                {
                    if (systemColumn == colIndexName)
                    {
                        continue; //name-column is already filled
                    }
                    if (noIncomeYear)
                    {
                        factorRow.Cells[systemColumn.Name].Value = _factorValueInvalid;
                    }
                    else
                    {
                        CountryConfig.SystemRow systemRow = systemColumn.Tag as CountryConfig.SystemRow;
                        string systemYear = systemRow.Year != null && systemRow.Year != string.Empty ? systemRow.Year
                                            : EM_Helpers.ExtractSystemYear((systemColumn.Tag as CountryConfig.SystemRow).Name);
                        // in the display, round the number to 4 digits - also make sure that you display dot regardless of the windows decimal separator. CalculateFactor takes care of all this...
                        factorRow.Cells[systemColumn.Name].Value = CalculateFactor(indexName, txtIncomeYear.Text, systemYear);
                    }
                }
            }
        }
示例#9
0
 private bool AcceptRestrictions()
 {
     if (EM_AppContext.Instance.IsAnythingOpen(false))
     {
         UserInfoHandler.ShowInfo("Deleting extensions needs all countries to be closed."); return(false);
     }
     return(UserInfoHandler.GetInfo("Please note that the necessary changes for countries using this/these extension(s) are accomplished once the country is next opened (automatically, but with a user request).",
                                    MessageBoxButtons.OKCancel) == DialogResult.OK);
 }
示例#10
0
 void btnOK_Click(object sender, EventArgs e)
 {
     if (GetSelectedProject() == null)
     {
         UserInfoHandler.ShowInfo("Please select a project.");
         return;
     }
     DialogResult = DialogResult.OK;
     Close();
 }
 private void btnDeleteRow_Click(object sender, EventArgs e)
 {
     if (dgvRates.SelectedRows == null || dgvRates.SelectedRows.Count == 0)
     {
         UserInfoHandler.ShowInfo("Please select the (whole) rows you want to remove.");
     }
     else
     {
         dgvRates.RemoveSelectedRows();
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!dgvRates.verifyNumericValues(out string problems))
                {
                    UserInfoHandler.ShowError("There are cells with invalid values!" + Environment.NewLine + problems);
                    return;
                }
                updatedExRates = new List <ExchangeRate>();
                DataTable dtExRates = dgvRates.GetDataTable();
                foreach (DataRow row in dtExRates.Rows)
                {
                    if (row[colValidFor.Name] == DBNull.Value || row.Field <string>(colValidFor.Name).ToString() == string.Empty)
                    {
                        continue;
                    }
                    string defaultCol = string.Empty;
                    switch (row.Field <string>(colDefault.Name))
                    {
                    case ExchangeRate.JUNE30: defaultCol = colJune30.Name; break;

                    case ExchangeRate.YEARAVERAGE: defaultCol = colYearAverage.Name; break;

                    case ExchangeRate.FIRSTSEMESTER: defaultCol = colFirstSemester.Name; break;

                    case ExchangeRate.SECONDSEMESTER: defaultCol = colSecondSemester.Name; break;
                    }
                    if (row[defaultCol] == DBNull.Value)
                    {
                        UserInfoHandler.ShowInfo(string.Format("{0} ({1}): Default ({2}) must not be empty.",
                                                               row.Field <string>(colCountry.Name), row.Field <string>(colValidFor.Name), defaultCol)); return;
                    }
                    updatedExRates.Add(new ExchangeRate()
                    {
                        Country        = row.Field <string>(colCountry.Name),
                        June30         = row[colJune30.Name] == DBNull.Value ? -1 : double.Parse(row[colJune30.Name].ToString()),
                        YearAverage    = row[colYearAverage.Name] == DBNull.Value ? -1 : double.Parse(row[colYearAverage.Name].ToString()),
                        FirstSemester  = row[colFirstSemester.Name] == DBNull.Value ? -1 : double.Parse(row[colFirstSemester.Name].ToString()),
                        SecondSemester = row[colSecondSemester.Name] == DBNull.Value ? -1 : double.Parse(row[colSecondSemester.Name].ToString()),
                        Default        = row.Field <string>(colDefault.Name),
                        ValidFor       = row.Field <string>(colValidFor.Name)
                    });
                }

                AssessChanges(); // check whether any country files need to be updated
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); return; }

            DialogResult = DialogResult.OK;
            Close();
        }
        void btnRun_Click(object sender, EventArgs e)
        {
            _selectedComponents = GatherComponents();
            if (_selectedComponents.Count == 0 && !IsPatternSearchForSingleComponent())
            {
                UserInfoHandler.ShowInfo("None of the selected components are in use");
                return;
            }

            _selectedSystemIDs.Clear();
            foreach (int index in lstSystems.CheckedIndices)
            {
                _selectedSystemIDs.Add(_systemRows.ElementAt(index).ID);
            }

            if (_usedComponenets == null)
            {
                _usedComponenets = new List <UsedComponent>();
            }
            _usedComponenets.Clear();

            //the handler passed to the progress indicator will do the work (see below)
            ProgressIndicator progressIndicator = new ProgressIndicator(ListUsage_BackgroundEventHandler, "Assessing usage of selected components");

            if (progressIndicator.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;                          //user cancelled the procedure
            }
            DoPatternSearchForSingleComponent(); //pattern-search has to be treated differently

            //display the found usages of selected components
            lvComponents.Items.Clear();
            foreach (UsedComponent usedComponent in _usedComponenets)
            {
                string       selectedComponent     = (usedComponent._tag as string).Split(_separator).ElementAt(0); //the component (e.g. tu_household_sl, ils_dispy, ...)
                string       selectedComponentType = (usedComponent._tag as string).Split(_separator).ElementAt(1); //the type of the component (e.g. assessment unit, incomelist, ...)
                ListViewItem listViewItem          = lvComponents.Items.Add(selectedComponent);
                listViewItem.SubItems.Add(selectedComponentType);
                listViewItem.SubItems.Add(usedComponent._policyName);       //used in policy
                listViewItem.SubItems.Add(usedComponent._functionName);     //used in function
                listViewItem.SubItems.Add(usedComponent._parameterName);    //used in parameter
                listViewItem.SubItems.Add(usedComponent._row);              //used in system(s)
                string systemNames = string.Empty;
                foreach (string systemName in usedComponent._systemNames)
                {
                    systemNames += systemName + " ";
                }
                listViewItem.SubItems.Add(systemNames);
                listViewItem.Tag = usedComponent._node; //to be able to jumpt to the respective parameter
            }
        }
示例#14
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (txtDestinationFolder.Text.Equals(String.Empty))
            {
                UserInfoHandler.ShowInfo("Please indicate a valid 'Project Path' for dowloading the latest online bundle."); return;
            }
            else if (!Directory.Exists(txtDestinationFolder.Text))
            {
                UserInfoHandler.ShowInfo("Please indicate an existing 'Project Path' for storing the latest online bundle."); return;
            }
            _projectContent.selections = GetChoices();
            DialogResult = System.Windows.Forms.DialogResult.OK;

            Close();
        }
        void btnOK_Click(object sender, EventArgs e)
        {
            List <VCAdministrator.UnitExistence> selectedUnits = GetSelected();

            if (selectedUnits.Count() == 0)
            {
                UserInfoHandler.ShowInfo("Please, select at least one unit.");
                return;
            }
            else
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
        void SwitchablePoliciesForm_Load(object sender, EventArgs e)
        {
            string helpPath; EM_AppContext.Instance.GetHelpPath(out helpPath); helpProvider.HelpNamespace = helpPath;

            if (EM_AppContext.Instance.IsVariablesFormOpen())
            {
                UserInfoHandler.ShowInfo("Please close the administration tool for variables before administrating switchable policies.");
                Close();
            }

            if (!OptionalWarningsManager.Show(OptionalWarningsManager._administrateSwitchablePoliciesWarning))
            {
                Close();
            }
        }
        List <DataGridViewRow> GetIncluded(bool checkForNoSelection = false, bool forceCheckAll = false)
        {
            List <DataGridViewRow> includedRows = new List <DataGridViewRow>();

            foreach (DataGridViewRow row in grid.Rows)
            {
                if (forceCheckAll || EM_Helpers.SaveConvertToBoolean(row.Cells[colInclude.Index].Value))
                {
                    includedRows.Add(row);
                }
            }
            if (checkForNoSelection && includedRows.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select at least one unit, by ticking the box in the column 'Include'.");
            }
            return(includedRows);
        }
示例#18
0
        void btnRemoveBundles_Click(object sender, EventArgs e)
        {
            if (lvBundles.CheckedItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select the bundles you want to remove."); return;
            }

            string warningContent = (_removeReleases) ? Environment.NewLine + Environment.NewLine + "This will remove an already commited merge!" : string.Empty;

            if (UserInfoHandler.GetInfo("Are you sure you want to irrevocably delete " +
                                        (lvBundles.CheckedItems.Count == 1 && warningContent == string.Empty ? "this item?" : "these items?" +
                                         warningContent), MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            List <ReleaseInfo> bundles = new List <ReleaseInfo>();

            foreach (ListViewItem item in lvBundles.CheckedItems)
            {
                bundles.Add(item.Tag as ReleaseInfo);
            }

            Cursor = Cursors.WaitCursor;
            bool success = _vcAPI.RemoveReleases(bundles, _vcAPI.vc_projectInfo.ProjectId);

            if (success)
            {
                UserInfoHandler.ShowSuccess("Removal accomplished.");
            }
            else
            {
                UserInfoHandler.ShowError(_vcAPI.GetErrorMessage());
            }
            Cursor = Cursors.Default;

            Close();
        }
        void btnExport_Click(object sender, EventArgs e)
        {
            if (lvComponents.Items.Count == 0)
            {
                UserInfoHandler.ShowInfo("There are no component-use-search results which can be exported.");
                return;
            }
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Text files (*.txt)|*.txt";
            openFileDialog.CheckPathExists  = true;
            openFileDialog.CheckFileExists  = false;
            openFileDialog.AddExtension     = true;
            openFileDialog.Multiselect      = false;
            openFileDialog.InitialDirectory = EM_AppContext.FolderOutput;

            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            DeveloperInfo.DeveloperInfoTools.ExportListView(lvComponents, Path.GetDirectoryName(openFileDialog.FileName), Path.GetFileName(openFileDialog.FileName));
        }
        //try to correct if file names (cc.xml and cc_DataConfig.xml) do notcorrespond to ShortName stored in cc.xml
        void CheckForCorrespondenceOfCountryShortName(bool informIfInconsistent = true)
        {
            try
            {
                if (_countryConfigFacade.GetCountryShortName().ToLower() == _shortName.ToLower())
                {
                    return; //short name corresponds - everything ok
                }
                if (informIfInconsistent)
                {
                    UserInfoHandler.ShowInfo("Filenames do not correspond to the short name stored within the files."
                                             + Environment.NewLine + _countryConfigFacade.GetCountryShortName() + " versus " + _shortName
                                             + Environment.NewLine + "Note that this will be corrected for you.");
                }

                _countryConfigFacade.GetCountryRow().ShortName = _shortName;
                WriteXML();
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
        bool CheckFieldValidity()
        {
            if (cmbReleases.SelectedIndex < 0)
            {
                UserInfoHandler.ShowInfo("Please select a release."); return(false);
            }

            _downloadActions.Clear();

            string undefUnits = string.Empty; int undefUnitsCount = 0, actionUnitsCount = 0, mergeCount = 0;

            foreach (var ui in _unitInfos)  // _downloadActions needs to be in the same order as _unitInfos ...
            {
                DataGridViewRow row = null; // ... therefore search for the correct row (users can change order sort-column-actions)
                foreach (DataGridViewRow r in dgvContent.Rows)
                {
                    if ((long)r.Tag == ui.UnitId)
                    {
                        row = r; break;
                    }
                }

                if (row.Cells[colGetReleaseVersion.Index].ReadOnly)
                {
                    _downloadActions.Add(DownloadAction.noAction);
                }
                else if (EM_Helpers.SaveConvertToBoolean(row.Cells[colKeepUIVersion.Index].Value))
                {
                    _downloadActions.Add(DownloadAction.noAction);
                }
                else if (EM_Helpers.SaveConvertToBoolean(row.Cells[colGetMergeSupport.Index].Value))
                {
                    _downloadActions.Add(DownloadAction.getMergeSupport); ++actionUnitsCount; ++mergeCount;
                }
                else if (EM_Helpers.SaveConvertToBoolean(row.Cells[colGetReleaseVersion.Index].Value))
                {
                    _downloadActions.Add(DownloadAction.getReleaseVersion); ++actionUnitsCount;
                }
                else
                {
                    VCAdministrator.AddUnitToMessage(ref undefUnits, row.Cells[colUnit.Index].Value.ToString()); ++undefUnitsCount;
                }
            }

            if (undefUnitsCount > 0)
            {
                UserInfoHandler.ShowInfo("Please make a choice for each unit, where user-interface-version and Release-version differ." +
                                         Environment.NewLine + string.Format("A choice is missing for unit{0} {1}.", undefUnitsCount > 1 ? "s" : string.Empty, undefUnits));
                return(false);
            }

            if (actionUnitsCount == 0)
            {
                UserInfoHandler.ShowInfo("Your choices do not require any download-action." + Environment.NewLine +
                                         "Please change your choices or close the dialog with Cancel.");
                return(false);
            }

            if (mergeCount > 0 && txtAlternativeFolder.Text != string.Empty)
            {
                UserInfoHandler.ShowInfo("Downloading to an alternative destination is not possible if 'Merge Support' is requested for any unit.");
                return(false);
            }

            if (txtAlternativeFolder.Text != string.Empty && !System.IO.Directory.Exists(txtAlternativeFolder.Text))
            {
                UserInfoHandler.ShowInfo("Please select an existing folder for the alternative destination."); return(false);
            }

            return(true);
        }
示例#22
0
        void btnDefineContent_Click(object sender, EventArgs e)
        {
            if (chkProjectOnDisk.Checked)
            {
                if (!CountryAdministrator.ContainsEuromodFileStructure(txtBasePath.Text))
                {
                    UserInfoHandler.ShowInfo($"Before you can define the content you have to indicate a folder containing the {DefGeneral.BRAND_TITLE} file structure as 'Base Project' (field 'Project on Disk').");
                    return;
                }
                string baseProjectPath = EMPath.AddSlash(txtBasePath.Text).ToLower();
                if (_projectContent != null && _projectContent.baseProjectPath != baseProjectPath)
                {
                    _projectContent = null; //project content was defined before, but for another base-project
                }
                if (_projectContent == null)
                {
                    if (!AssessDiskBaseProjectContent(baseProjectPath, out _projectContent))
                    {
                        return;
                    }
                }
            }
            else //chkProjectOnVC.Checked = true
            {
                if (cmbBaseProjects.SelectedIndex < 0)
                {
                    UserInfoHandler.ShowInfo("Before you can define the content you have to define a 'Base Project' (select from list 'Project on VC').");
                    return;
                }
                if (cmbSelectVersion.SelectedIndex < 0)
                {
                    UserInfoHandler.ShowInfo("Before you can define the content you have to select a Version for the 'Base Project' (select from list 'Project on VC').");
                    return;
                }

                string currentSelectedVersionIndex = cmbSelectVersion.SelectedItem.ToString();

                ProjectNode project = (cmbBaseProjects.Tag as List <ProjectNode>).ElementAt(cmbBaseProjects.SelectedIndex);

                if ((_projectContent != null && _projectContent.baseProjectId != project.Id) || (_projectContent != null && _projectContent.baseProjectId == project.Id && _projectContent.selectedRelease != cmbSelectVersion.SelectedItem.ToString()))
                {
                    _projectContent = null;                     //project content was defined before, but for another base-project
                }
                _selectedVersion = currentSelectedVersionIndex; //The selected version is updated

                if (_projectContent == null)
                {
                    if (!AssessVCBaseProjectContent(out _projectContent))
                    {
                        return;
                    }
                }
            }

            VCProjectContent projectContent = new VCProjectContent(_projectContent);

            if (projectContent.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            projectContent.GetChoices(out _projectContent.selections, out _projectContent.selectedYears);
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstCountries.SelectedItems.Count == 0 && lstSystems.SelectedItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select the countries and/or systems you want to include into the project."); return;
            }

            if (txtProjectName.Text == string.Empty || txtProjectPath.Text == string.Empty)
            {
                UserInfoHandler.ShowError("Please select a valid Project Name and/or Project Path."); return;
            }
            projectPath = EMPath.AddSlash(EMPath.AddSlash(txtProjectPath.Text) + txtProjectName.Text);
            if (!EM_Helpers.IsValidFileName(projectPath))
            {
                UserInfoHandler.ShowInfo(projectPath + " is not a valid folder name for the new project."); return;
            }

            Cursor = Cursors.WaitCursor; bool undo = false;
            try
            {
                // first copy the whole EuromodFiles folder to the respective path, to then adapt the copy
                if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, txtProjectPath.Text, txtProjectName.Text))
                {
                    Cursor = Cursors.Default; return;
                }
                undo = true;

                // delete all unnecessary files and folders (but do not report or stop if any of this fails)
                EMPath emPath = new EMPath(EM_AppContext.FolderEuromodFiles);
                DeleteFolder(ReplacePath(emPath.GetFolderLog()));
                ClearFolder(ReplacePath(EM_AppContext.FolderOutput));
                ClearFolder(ReplacePath(emPath.GetFolderTemp()));
                DeleteFile(ReplacePath(Path.Combine(emPath.GetFolderConfig(true), "VersionControl.xml")));

                string        folderCountries = ReplacePath(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles));
                List <string> selCountries    = new List <string>(); foreach (var item in lstCountries.SelectedItems)
                {
                    selCountries.Add(item.ToString().ToLower());
                }
                ClearFolder(folderCountries, selCountries);

                // delete all unnecessary systems
                List <string> selSystems = null;
                if (lstSystems.SelectedItems.Count > 0 && lstSystems.SelectedItems.Count != lstSystems.Items.Count)
                {
                    selSystems = new List <string>(); foreach (var item in lstSystems.SelectedItems)
                    {
                        selSystems.Add(item.ToString().ToLower());
                    }
                }
                foreach (string cc in selCountries)
                {
                    DeleteFile(EMPath.AddSlash(projectPath + cc) + cc + "_in_use.txt");

                    if (selSystems == null)
                    {
                        continue;                     // if all system/years are selected or nothing is selected, assume that user does not want to "reduce" systems
                    }
                    Country             country = new Country(cc);
                    CountryConfigFacade ccf     = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dcf     = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    List <CountryConfig.SystemRow> delSystems = new List <CountryConfig.SystemRow>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (radShowSystems.Checked)
                        {
                            if (!selSystems.Contains(system.Name.ToLower()))
                            {
                                delSystems.Add(system);
                            }
                        }
                        else
                        {
                            string systemYear = system.Year == null || system.Year == string.Empty ? EM_Helpers.ExtractSystemYear(system.Name) : system.Year;
                            if (!selSystems.Contains(systemYear))
                            {
                                delSystems.Add(system);
                            }
                        }
                    }

                    List <DataConfig.DBSystemConfigRow> delDBSysCons = new List <DataConfig.DBSystemConfigRow>();
                    List <string> delSystemIds = (from d in delSystems select d.ID).ToList();
                    foreach (DataConfig.DataBaseRow dataSet in dcf.GetDataBaseRows())
                    {
                        foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dcf.GetDBSystemConfigRows(dataSet.ID))
                        {
                            if (delSystemIds.Contains(dbSystemConfig.SystemID))
                            {
                                delDBSysCons.Add(dbSystemConfig);
                            }
                        }
                    }

                    foreach (CountryConfig.SystemRow delSystem in delSystems)
                    {
                        delSystem.Delete();
                    }
                    foreach (DataConfig.DBSystemConfigRow delDBSysCon in delDBSysCons)
                    {
                        delDBSysCon.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                }
                UserInfoHandler.ShowSuccess("Successfully created project folder " + projectPath + ".");
                Close();
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError(exception.Message);
                if (undo)
                {
                    try { if (Directory.Exists(projectPath))
                          {
                              Directory.Delete(projectPath, true);
                          }
                    } catch { }
                }
            }
            Cursor = Cursors.Default;
        }
示例#24
0
        static void Generate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

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

            //assess the name of the new EuromodFiles-folder in accordance to the version number
            DirectoryInfo sourceFolder = new DirectoryInfo(EM_AppContext.FolderEuromodFiles);
            string        folderEMF    = "EuromodFiles_" + _publicVersionNumber;

            if (!EM_Helpers.IsValidFileName(folderEMF))
            {
                UserInfoHandler.ShowInfo(folderEMF + " is not a valid folder name. Please change the version number.");
                e.Cancel = true; return;
            }

            //first copy the whole EuromodFiles folder to the respective path
            if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, _publicVersionPath, folderEMF))
            {
                e.Cancel = true; return;
            }

            string fullPublicPath = _publicVersionPath + EMPath.AddSlash(folderEMF);

            //then adapt the copy
            string folderCountries =
                EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();

                //remove private systems, policies and datasets of each country
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }                                                                      //user pressed Cancel button: see above

                    Country             country             = countries[i];
                    CountryConfigFacade countryConfigFacade = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dataConfigFacade    = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    //assess which systems, policies and datasets are private
                    List <CountryConfig.SystemRow>    privateSystems    = new List <CountryConfig.SystemRow>();    //systems
                    List <CountryConfig.PolicyRow>    privatePolicies   = new List <CountryConfig.PolicyRow>();    //policies
                    List <CountryConfig.FunctionRow>  privateFunctions  = new List <CountryConfig.FunctionRow>();  //functions
                    List <CountryConfig.ParameterRow> privateParameters = new List <CountryConfig.ParameterRow>(); //parameters
                    List <string> privateSystemIDs = new List <string>();                                          //necessary for afterwards identifying database-connections of private systems
                    foreach (CountryConfig.SystemRow system in countryConfigFacade.GetSystemRows())
                    {
                        if (system.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateSystems.Add(system);
                            privateSystemIDs.Add(system.ID);
                        }
                        else
                        {
                            foreach (CountryConfig.PolicyRow policy in system.GetPolicyRows())
                            {
                                if (policy.Private == DefPar.Value.YES)
                                {
                                    privatePolicies.Add(policy);
                                }
                                else
                                {
                                    if (policy.PrivateComment != null && policy.PrivateComment != string.Empty)
                                    {
                                        policy.PrivateComment = string.Empty; //remove private policy-comment if there is any
                                    }
                                    foreach (CountryConfig.FunctionRow function in policy.GetFunctionRows())
                                    {
                                        if (function.Private == DefPar.Value.YES)
                                        {
                                            privateFunctions.Add(function);
                                        }
                                        else
                                        {
                                            if (function.PrivateComment != null && function.PrivateComment != string.Empty)
                                            {
                                                function.PrivateComment = string.Empty; //remove private function-comment if there is any
                                            }
                                            foreach (CountryConfig.ParameterRow parameter in function.GetParameterRows())
                                            {
                                                if (parameter.Private == DefPar.Value.YES)
                                                {
                                                    privateParameters.Add(parameter);
                                                }
                                                else if (parameter.PrivateComment != null && parameter.PrivateComment != string.Empty)
                                                {
                                                    parameter.PrivateComment = string.Empty; //remove private parameter-comment if there is any
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    List <DataConfig.DataBaseRow>       privateDataSets        = new List <DataConfig.DataBaseRow>();       //datasets
                    List <DataConfig.DBSystemConfigRow> privateDBSystemConfigs = new List <DataConfig.DBSystemConfigRow>(); //database-connections of private systems
                    foreach (DataConfig.DataBaseRow dataSet in dataConfigFacade.GetDataBaseRows())
                    {
                        if (dataSet.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateDataSets.Add(dataSet);
                        }
                        else
                        {
                            foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dataConfigFacade.GetDBSystemConfigRows(dataSet.ID))
                            {
                                if (privateSystemIDs.Contains(dbSystemConfig.SystemID))
                                {
                                    privateDBSystemConfigs.Add(dbSystemConfig);
                                }
                            }
                        }
                    }

                    //remove user-set node colors
                    countryConfigFacade.RemoveAllNodeColors();

                    //restore or install default base-system-colouring
                    countryConfigFacade.setAutomaticConditionalFormatting(true);

                    //remove private systems
                    if (countryConfigFacade.GetCountryRow().Private == DefPar.Value.YES || //if country is private or
                        privateSystems.Count == countryConfigFacade.GetSystemRows().Count) //there are no systems left, delete country
                    {
                        Directory.Delete(folderCountries + country._shortName, true);
                        country.SetCountryConfigFacade(null);
                        country.SetDataConfigFacade(null);
                        continue;
                    }
                    else //otherwise delete private systems
                    {
                        foreach (CountryConfig.SystemRow privateSystem in privateSystems)
                        {
                            privateSystem.Delete();
                        }
                    }

                    //remove private parameters
                    foreach (CountryConfig.ParameterRow privateParameter in privateParameters)
                    {
                        privateParameter.Delete();
                    }

                    //remove private functions
                    foreach (CountryConfig.FunctionRow privateFunction in privateFunctions)
                    {
                        privateFunction.Delete();
                    }

                    //remove private policies
                    foreach (CountryConfig.PolicyRow privatePolicy in privatePolicies)
                    {
                        privatePolicy.Delete();
                    }

                    //remove private datasets
                    foreach (DataConfig.DataBaseRow privateDataSet in privateDataSets)
                    {
                        privateDataSet.Delete();
                    }

                    //remove database-connections of private systems
                    foreach (DataConfig.DBSystemConfigRow privateDBSystemConfig in privateDBSystemConfigs)
                    {
                        privateDBSystemConfig.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                    country.SetCountryConfigFacade(null);
                    country.SetDataConfigFacade(null);

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 80.0));
                }

                //remove private add-ons
                string folderAddOns = EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_AddOns(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));
                foreach (Country addOn in CountryAdministrator.GetAddOns())
                {
                    bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(true);
                    CountryConfigFacade addOnConfigFacade = addOn.GetCountryConfigFacade(true, folderAddOns + (oldStyle ? string.Empty : addOn._shortName));
                    if (addOnConfigFacade.GetCountryRow().Private != DefPar.Value.YES)
                    {
                        continue;
                    }
                    if (oldStyle)
                    {
                        File.Delete(folderAddOns + addOn._shortName + ".xml");
                    }
                    else
                    {
                        Directory.Delete(folderAddOns + addOn._shortName, true);
                    }
                    addOn.SetCountryConfigFacade(null);
                }

                // remove the "other" column from the variables file
                string          pathVarConfig = new EMPath(EM_AppContext.FolderEuromodFiles).GetVarFilePath(true).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                VarConfigFacade vcf           = new VarConfigFacade(pathVarConfig);
                if (vcf.LoadVarConfig())
                {
                    foreach (VarConfig.CountryLabelRow r in
                             from l in vcf._varConfig.CountryLabel where l.Country.ToLower() == "other" select l)
                    {
                        r.Delete();
                    }
                    vcf.Commit(); vcf.WriteXML(pathVarConfig);
                }

                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }                                                                      //user pressed Cancel button: see above

                //change version number
                string txtVersionPath = EMPath.Folder_Config(EM_AppContext.FolderEuromodFiles) + "EuromodVersion.txt";
                txtVersionPath = txtVersionPath.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                using (StreamWriter versionFile = new StreamWriter(txtVersionPath))
                {
                    versionFile.WriteLine(_publicVersionNumber);
                    versionFile.WriteLine("PUBLIC VERSION");
                }

                //remove private rows from log file
                string logFile = new EMPath(EM_AppContext.FolderEuromodFiles).GetEmLogFilePath(); // determine the path of the em_log-file in the public folder
                logFile = logFile.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                backgroundWorker.ReportProgress(100);
                if (File.Exists(logFile))
                {
                    AdaptLogFile(logFile);
                }

                //take care to not have any "xx_in_use.txt" files in the release
                try
                {
                    foreach (string inUseFile in Directory.GetFiles(fullPublicPath, "*_in_use.txt", SearchOption.AllDirectories))
                    {
                        File.Delete(inUseFile);
                    }
                }
                catch (Exception exception)
                {
                    //do nothing if this fails
                    UserInfoHandler.RecordIgnoredException("PublicVersion.Generate_BackgroundEventHandler", exception);
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
                e.Cancel = true; //stop the process and allow progress indicator to set dialog result to Cancel
            }
        }