Exemple #1
0
        private void CheckAlterntivesValues()
        {
            controller._alternatives.Alternatives.Clear();
            for (int i = 0; i < dataGridViewAlternatives.Rows.Count - 1; ++i)
            {
                AlternativeController alternative = new AlternativeController();
                DataGridViewRow       row         = dataGridViewAlternatives.Rows[i];
                if (row.Cells[0].Value.ToString() == "")
                {
                    throw new Exception("Title of alterntive #" + (i + 1).ToString() + " is missed");
                }
                alternative.Title = row.Cells[0].Value.ToString();

                for (int j = 0; j < controller._criterias.Criterias.Count; ++j)
                {
                    if (controller._criterias.Criterias[j].CriteriaType == CriteriaTypeEnum.Quantitative)
                    {
                        DataGridViewTextBoxCell cell = (DataGridViewTextBoxCell)row.Cells[j + 1];
                        double value;
                        if (cell.Value.ToString() == "" || double.TryParse(cell.Value.ToString(), out value) == false)
                        {
                            throw new Exception("Value of alternative #" + (i + 1).ToString() + " and criteria #" + (j + 1).ToString() + " is invalid.");
                        }
                        if (!(value >= controller._criterias.Criterias[j].MinValue && value <= controller._criterias.Criterias[j].MaxValue))
                        {
                            throw new Exception("Value of alternative #" + (i + 1).ToString() + " and criteria #" + (j + 1).ToString() + " doesn't match MinMax interval.");
                        }
                        alternative.Values.Add(value);
                    }
                    else
                    {
                        DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)row.Cells[j + 1];
                        double value = (cell.FormattedValue.ToString() != "" ?
                                        QualitativeToDouble[cell.FormattedValue.ToString()] :
                                        -1);
                        if (value.ToString() == "-1")
                        {
                            throw new Exception("Value of alternative #" + (i + 1).ToString() + " and criteria #" + (j + 1).ToString() + " is invalid.");
                        }
                        if (!(value >= controller._criterias.Criterias[j].MinValue && value <= controller._criterias.Criterias[j].MaxValue))
                        {
                            throw new Exception("Value of alternative #" + (i + 1).ToString() + " and criteria #" + (j + 1).ToString() + " doesn't match MinMax interval.");
                        }
                        alternative.Values.Add(value);
                    }
                }
                controller._alternatives.Alternatives.Add(alternative);
            }
        }
Exemple #2
0
        private void AddAlternativeValuesTiDataGrid(AlternativeController alternative)
        {
            dataGridViewAlternatives.Rows.Add();
            DataGridViewRow NewRow = dataGridViewAlternatives.Rows[dataGridViewAlternatives.Rows.Count - 2];

            NewRow.Cells[0].Value = alternative.Title;
            for (int i = 0; i < controller._criterias.Criterias.Count; ++i)
            {
                if (controller._criterias.Criterias[i].CriteriaType == CriteriaTypeEnum.Qualitative)
                {
                    NewRow.Cells[i + 1].Value = DoubleToQulitative[alternative.Values[i]];
                }
                else
                {
                    NewRow.Cells[i + 1].Value = alternative.Values[i].ToString();
                }
            }
        }