private void RVHHLevelVarForm_Shown(object sender, EventArgs e) { try { // get all HH-level variables from the variables file List <string> hhVars = (from v in EM_AppContext.Instance.GetVarConfigFacade().GetVarConfig().Variable where VariablesManager.IsHHLevel(v) && v.Name.ToLower() != DefVarName.IDHH.ToLower() select v.Name.ToLower()).ToList(); // gather the files to check: those fulfilling the pattern and the custom ones if (Directory.Exists(dataPath)) { foreach (string f in Directory.GetFiles(dataPath, namePattern)) { dataToCheck.Add(Path.Combine(dataPath, f)); } } // do the checking, showing a progress bar // the background-worker gets 2 parameters: // - the list of HH-level variables and // - the list of files to check ProgressIndicator progressIndicator = new ProgressIndicator(CheckData_BackgroundEventHandler, "Checking Data ...", new Tuple <List <string>, List <string> >(hhVars, dataToCheck)); if (progressIndicator.ShowDialog() != DialogResult.OK) { Close(); return; } // user pressed Cancel // interpret the results // the background-worker returns 2 results: // - the list of variables, each variable with a list of the file(s) that caused problems, and an empty list if there are no problems // - a (hopefully empty) list of critical errors, i.e. one for each file that could not be analysed Dictionary <string, List <string> > hhVarResults = (progressIndicator.Result as Tuple <Dictionary <string, List <string> >, List <string> >).Item1; List <string> problemData = (progressIndicator.Result as Tuple <Dictionary <string, List <string> >, List <string> >).Item2; if (problemData.Count > 0) { UserInfoHandler.ShowError("The following data could not be checked:" + Environment.NewLine + string.Join(Environment.NewLine, problemData)); if (problemData.Count == dataToCheck.Count) { Close(); return; } // checking failed for all data-files } // show the results in the grid foreach (var result in hhVarResults) { string problems = result.Value.Count == 0 ? "No problems found for the checked files" : string.Join(SEPARATOR, result.Value); dgvVar.Rows.Add(result.Key, problems); } } catch (Exception exception) { UserInfoHandler.ShowException(exception); Close(); } }
internal override bool Perform() { DataGridViewRow changedRow = _dgvVariables.Rows[_eventArgs.RowIndex]; VarConfig.VariableRow variableRow = changedRow.Tag as VarConfig.VariableRow; if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colVariableName)) { //variables name edited if (variableRow.Name != changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString()) { //only (change and) return true if actually changed variableRow.Name = changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString(); int columnIndexAutoLabel = _variablesForm.dgvVariables.Columns.IndexOf(_variablesForm.colAutomaticLabel); variableRow.AutoLabel = changedRow.Cells[columnIndexAutoLabel].Value.ToString(); return(true); } } if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colMonetary)) {//checkbox monetary edited bool newValue_IsMonetary = (bool)changedRow.Cells[_eventArgs.ColumnIndex].Value; if (VariablesManager.IsMonetary(variableRow) && !newValue_IsMonetary) {//current value monetary, new value non-monetary variableRow.Monetary = "0"; return(true); } if (!VariablesManager.IsMonetary(variableRow) && newValue_IsMonetary) {//current value non-monetary, new value monetary variableRow.Monetary = "1"; return(true); } } if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colHHLevel)) {//checkbox HH Level edited bool newValue_IsHHLevel = (bool)changedRow.Cells[_eventArgs.ColumnIndex].Value; if (VariablesManager.IsHHLevel(variableRow) && !newValue_IsHHLevel) {//current value hh-level, new value ind-level variableRow.HHLevel = "0"; return(true); } if (!VariablesManager.IsHHLevel(variableRow) && newValue_IsHHLevel) {//current value ind-level, new value hh-level variableRow.HHLevel = "1"; return(true); } } return(false); }
internal override bool Perform() { VarConfig.VariableRow variableRow = _varConfigFacade.AddVariable(); int index = 0; if (_dgvVariables.SelectedRows.Count == 1) { index = _dgvVariables.Rows.IndexOf(_dgvVariables.SelectedRows[0]) + 1; } _dgvVariables.Rows.Insert(index, variableRow.Name, VariablesManager.IsMonetary(variableRow), VariablesManager.IsHHLevel(variableRow), false, variableRow.AutoLabel); _dgvVariables.Rows[index].Tag = variableRow; _dgvVariables.Rows[index].Cells[0].Selected = true; //set input focus to just added row (selecting row instead of cell does not work) _dgvVariables.Select(); //grid view must be selected too, otherwise another list may have the input focus return(true); }