Esempio n. 1
0
 private void btnLevels_Click(object sender, EventArgs e)
 {
     if (this.t.Any(x => x.Text == ""))
     {
         MessageBox.Show("Заполните все поля!");
         return;
     }
     try
     {
         if (this.t.Any(x => Convert.ToInt32(x.Text) < 2 || Convert.ToInt32(x.Text) > 10))
         {
             MessageBox.Show("Проверьте правильность заполнения полей!");
             return;
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Проверьте правильность заполнения полей!");
         return;
     }
     for (int i = 0; i < AHP.criterias_q.Length; i++)
     {
         AHP.criterias_q[i] = Convert.ToInt32(t[i].Text);
     }
     TabHandle.MakeReadOnly(tabControl1.SelectedTab);
     TabCriteriasShow();
     tabControl1.SelectedTab    = tabPage2;
     (sender as Button).Visible = false;
 }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.t.Any(x => x.Text == ""))
            {
                MessageBox.Show("Заполните все поля!");
                return;
            }
            AHP.criterias.Clear();
            int ind = 0;

            for (int i = 0; i < AHP.criterias_q.Length; i++)
            {
                string[] crits = new string[AHP.criterias_q[i]];
                for (int j = 0; j < crits.Length; j++)
                {
                    crits[j] = t[ind].Text;
                    ind++;
                }
                AHP.criterias.Add(crits);
            }

            /*int l = 0;
             * for (int i = 0; i < AHP.criterias_q.Length - 1; i++)
             *  l += AHP.criterias_q[i];*/
            TabHandle.MakeReadOnly(tabControl1.SelectedTab);
            TabAlternativesShow();
            tabControl1.SelectedTab    = tabPage3;
            (sender as Button).Visible = false;
        }
Esempio n. 3
0
        private void btnCompAlt_Click(object sender, EventArgs e)
        {
            int q = AHP.alternatives.Length;

            double[,] matrix = new double[q, q];
            for (int j = 0; j < q; j++)
            {
                matrix[j, j] = 1;
            }
            for (int i = 0; i < q - 1; i++)
            {
                for (int j = i + 1; j < q; j++)
                {
                    double value = ParseValue(tboxes[j, i].Text);;

                    /*if (tboxes[j, i].Text.Length == 1)
                     *  value = Convert.ToDouble(tboxes[j, i].Text);
                     * else
                     *  value = Convert.ToDouble(tboxes[j, i].Text.Substring(tboxes[j, i].Text.IndexOf("/") + 1).ToString()) / Convert.ToDouble(tboxes[j, i].Text.Substring(0, tboxes[j, i].Text.IndexOf("/")).ToString());*/
                    matrix[i, j] = value;
                    matrix[j, i] = 1.0 / value;
                    if (matrix[i, j] == 0 || Double.IsInfinity(matrix[i, j]))
                    {
                        MessageBox.Show("Проверьте правильность заполнения полей!");
                        return;
                    }
                }
            }
            matrixes.Add(new PairedMatrix(curCriteria, AHP.alternatives, matrix));
            TabHandle.MakeReadOnly(tabControl1.SelectedTab);
            // если последнее сравнение
            if (Array.IndexOf(AHP.criterias[AHP.criterias.Count - 1], curCriteria) == AHP.criterias[AHP.criterias.Count - 1].Length - 1)
            {
                AHP.criteriasComparison.Add(new List <PairedMatrix>(matrixes));
                AHP.Calculate();
                matrixes.Clear(); // GC
                TabResultsShow();
                sort.Visible            = true;
                radioButton1.Visible    = true;
                radioButton2.Visible    = true;
                tabControl1.SelectedTab = tabPage6;
                tboxes = null;
            }
            else
            {
                curCriteria = AHP.criterias[AHP.criterias.Count - 1][Array.IndexOf(AHP.criterias[AHP.criterias.Count - 1], curCriteria) + 1];
                TabPage tabp = new TabPage();
                tabControl4.TabPages.Add(tabp);
                TabCompAltShow(ref tabp);
                tabControl4.SelectedTab = tabp;
            }
            (sender as Button).Visible = false;
        }
Esempio n. 4
0
        private static TextBox[,] GetTextBoxMatrix(TabPage tabp)
        {
            TextBox[] tmp = TabHandle.FindTextBoxes(tabp);
            TextBox[,] tboxes = new TextBox[(int)Math.Sqrt(tmp.Length), (int)Math.Sqrt(tmp.Length)];
            int ind = 0;

            for (int i = 0; i < tboxes.GetLength(0); i++)
            {
                for (int j = 0; j < tboxes.GetLength(1); j++)
                {
                    tboxes[j, i] = tmp[ind];
                    ind++;
                }
            }
            return(tboxes);
        }
Esempio n. 5
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (this.t.Any(x => x.Text == ""))
     {
         MessageBox.Show("Заполните все поля!");
         return;
     }
     AHP.alternatives = new string[AHP.alternatives_q];
     for (int i = 0; i < AHP.alternatives_q; i++)
     {
         AHP.alternatives[i] = t[i].Text;
     }
     TabHandle.MakeReadOnly(tabControl1.SelectedTab);
     TabCompCritShowFirst();
     tabControl1.SelectedTab = tabPage4;
     t = null;
     (sender as Button).Visible = false;
 }
Esempio n. 6
0
 private void Tab_Leave(object sender, EventArgs e)
 {
     if (editing)
     {
         DialogResult confirm = MessageBox.Show("Сохранить изменённые данные?", "Внимание!", MessageBoxButtons.YesNo);
         if (confirm == DialogResult.Yes)
         {
             saveDataToolStripMenuItem.PerformClick();
         }
         else
         {
             TabHandle.MakeReadOnly(tabControl1.SelectedTab);
             editing = false;
             editDataToolStripMenuItem.Enabled = true;
             saveDataToolStripMenuItem.Enabled = false;
         }
     }
 }
Esempio n. 7
0
        private void LoadData(DataHandle dh)
        {
            AHP.problemName    = dh.problemName;
            AHP.levels         = dh.levels;
            AHP.criterias_q    = dh.criterias_q;
            AHP.alternatives_q = dh.alternatives_q;
            if (dh.alternatives != null)
            {
                AHP.alternatives = dh.alternatives;
            }
            if (dh.criterias != null)
            {
                AHP.criterias = new List <string[]>(dh.criterias);
            }
            if (dh.results != null)
            {
                AHP.results = new List <KeyValuePair <string, double> >(dh.results);
                AHP.SortResults(false);
            }
            matrixes = new List <PairedMatrix>();

            for (int i = 0; i < dh.matrixs.Count; i++)
            {
                string[,] matrix = dh.matrixs[i].Value;
                double[,] res    = new double[matrix.GetLength(0), matrix.GetLength(1)];
                for (int k = 0; k < matrix.GetLength(0); k++)
                {
                    for (int s = 0; s < matrix.GetLength(1); s++)
                    {
                        string v = matrix[k, s];
                        if (v.Contains("/"))
                        {
                            res[k, s] = Convert.ToDouble(matrix[k, s].Substring(0, matrix[k, s].IndexOf("/"))) / Convert.ToDouble(matrix[k, s].Substring(matrix[k, s].IndexOf("/") + 1));
                        }
                        else
                        {
                            res[k, s] = Convert.ToDouble(matrix[k, s]);
                        }
                    }
                }
                matrixes.Add(new PairedMatrix(dh.matrixs[i].Key, res));
            }

            for (int i = 0; i < dh.criteriasComparison.Count; i++)
            {
                List <PairedMatrix> lpm = new List <PairedMatrix>();
                for (int j = 0; j < dh.criteriasComparison[i].Count; j++)
                {
                    string[,] matrix = dh.criteriasComparison[i][j].Value;
                    double[,] res    = new double[matrix.GetLength(0), matrix.GetLength(1)];
                    for (int k = 0; k < matrix.GetLength(0); k++)
                    {
                        for (int s = 0; s < matrix.GetLength(1); s++)
                        {
                            string v = matrix[k, s];
                            if (v.Contains("/"))
                            {
                                res[k, s] = Convert.ToDouble(matrix[k, s].Substring(0, matrix[k, s].IndexOf("/"))) / Convert.ToDouble(matrix[k, s].Substring(matrix[k, s].IndexOf("/") + 1));
                            }
                            else
                            {
                                res[k, s] = Convert.ToDouble(matrix[k, s]);
                            }
                        }
                    }
                    lpm.Add(new PairedMatrix(dh.criteriasComparison[i][j].Key, res));
                }
                AHP.criteriasComparison.Add(new List <PairedMatrix>(lpm));
            }

            // Начало
            tb_problemName.Text = dh.problemName;
            tb_levels.Text      = (dh.levels + 1).ToString();
            textBox1.Text       = dh.alternatives_q.ToString();
            if (dh.levels == 2)
            {
                textBox2.Text = dh.criterias_q[0].ToString();
            }
            TabHandle.MakeReadOnly(tabPage1);
            TabHandle.FindButton(tabPage1).Visible = false;
            if (dh.levels >= 3 && dh.criterias_q != null)
            {
                TabPage crL = new TabPage("Уровни критериев");
                crL.Name = "tabCrL";
                tabControl2.TabPages.Add(crL);
                TabCriteriaLevelsShow(crL);
                for (int i = 0; i < t.Length; i++)
                {
                    t[i].Text = dh.criterias_q[i].ToString();
                }
                TabHandle.MakeReadOnly(crL);
                TabHandle.FindButton(crL).Visible = false;
                tabControl2.SelectedTab           = tabControl2.TabPages[1];
            }
            TabCriteriasShow();

            // Критерии
            if (dh.criterias == null || dh.criterias.Count == 0)
            {
                if (dh.levels >= 3)
                {
                    tabControl2.SelectedTab = tabControl2.TabPages[1];
                }
                tabControl1.SelectedTab = tabPage2;
                return;
            }
            int ind = 0;

            for (int i = 0; i < dh.criterias.Count; i++)
            {
                for (int j = 0; j < dh.criterias[i].Length; j++)
                {
                    t[ind].Text = dh.criterias[i][j];
                    ind++;
                }
            }
            TabHandle.MakeReadOnly(tabPage2);
            TabHandle.FindButton(tabPage2).Visible = false;
            TabAlternativesShow();

            // Альтернативы
            if (dh.alternatives == null)
            {
                tabControl1.SelectedTab = tabPage3;
                return;
            }
            for (int i = 0; i < dh.alternatives.Length; i++)
            {
                t[i].Text = dh.alternatives[i];
            }
            TabHandle.MakeReadOnly(tabPage3);
            TabHandle.FindButton(tabPage3).Visible = false;

            TabCompCritShowFirst();

            // Сравнение критериев, tabPage4
            if (dh.criteriasComparison.Count == 0)
            {
                tabControl1.SelectedTab = tabPage4;
                return;
            }
            int alt_q = 0;

            //if (dh.criteriasComparison[dh.criteriasComparison.Count - 1][0].Key == dh.criterias[dh.criterias.Count - 1][0])
            if (dh.criteriasComparison.Count == AHP.levels)
            {
                alt_q = 1;
            }

            TabPage tabp = new TabPage();

            for (int i = 0; i < dh.criteriasComparison.Count - alt_q; i++)
            {
                for (int j = 0; j < dh.criteriasComparison[i].Count; j++)
                {
                    if (i != 0 || j != 0)
                    {
                        curCriteria = dh.criteriasComparison[i][j].Key;
                        tabp        = new TabPage();
                        tabControl3.TabPages.Add(tabp);
                        TabCompCritShow(ref tabp);
                    }
                    string[,] matrix = dh.criteriasComparison[i][j].Value;
                    for (int k = 0; k < matrix.GetLength(0) - 1; k++)
                    {
                        for (int s = k + 1; s < matrix.GetLength(1); s++)
                        {
                            tboxes[s, k].Text = matrix[k, s];
                        }
                    }
                    if (i == 0 && j == 0)
                    {
                        TabHandle.FindButton(tabControl3.TabPages[0]).Visible = false;
                        TabHandle.MakeReadOnly(tabControl3.TabPages[0]);
                    }
                    else
                    {
                        TabHandle.FindButton(tabp).Visible = false;
                        TabHandle.MakeReadOnly(tabp);
                    }
                }
                lvl++;
            }
            if (alt_q == 0 && dh.criteriasComparison.Count != (AHP.levels - 1))
            {
                bool done = false;
                for (int i = 0; i < dh.criterias.Count; i++)
                {
                    for (int j = 0; j < dh.criterias[i].Length; j++)
                    {
                        if (dh.criterias[i][j] == tabControl3.TabPages[tabControl3.TabPages.Count - 1].Name)
                        {
                            curCriteria = dh.criterias[i][j];
                            tabp        = new TabPage();
                            tabControl3.TabPages.Add(tabp);
                            TabCompCritShow(ref tabp);
                            done = true;
                        }
                    }
                }
                if (!done)
                {
                    curCriteria = dh.criterias[0][0];
                    tabp        = new TabPage();
                    tabControl3.TabPages.Add(tabp);
                    TabCompCritShow(ref tabp);
                }
            }

            if (dh.matrixs != null && dh.matrixs.Count != 0)
            {
                foreach (KeyValuePair <string, string[, ]> m in dh.matrixs)
                {
                    for (int l = 0; l < dh.criterias.Count - 1; l++)
                    {
                        foreach (string c in dh.criterias[l])
                        {
                            if (m.Key == c)
                            {
                                for (int i = 0; i < dh.matrixs.Count; i++)
                                {
                                    string[,] matrix = dh.matrixs[i].Value;
                                    for (int k = 0; k < matrix.GetLength(0) - 1; k++)
                                    {
                                        for (int s = k + 1; s < matrix.GetLength(1); s++)
                                        {
                                            tboxes[s, k].Text = matrix[k, s];
                                        }
                                    }
                                    TabHandle.FindButton(tabp).Visible = false;
                                    TabHandle.MakeReadOnly(tabp);
                                }
                                for (int i = 0; i < dh.criterias.Count - 1; i++)
                                {
                                    bool done = false;
                                    for (int j = 0; j < dh.criterias[i].Length; j++)
                                    {
                                        if (dh.criterias[i][j] == tabControl3.TabPages[tabControl3.TabPages.Count - 1].Name && !done && dh.criteriasComparison.Count != (AHP.levels - 1))
                                        {
                                            curCriteria = dh.criterias[i][j + 1];
                                            tabp        = new TabPage();
                                            tabControl3.TabPages.Add(tabp);
                                            TabCompCritShow(ref tabp);
                                            done = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Сравнение альтернатив, tabPage5
            if ((dh.matrixs != null && dh.matrixs.Any(x => !dh.criterias[dh.criterias.Count - 1].Contains(x.Key))) || tabControl3.TabPages.Count != (AHP.criterias_q.Sum() - AHP.criterias_q[AHP.criterias_q.Length - 1] + 1))
            {
                tabControl1.SelectedTab = tabPage4;
                tabControl3.SelectedTab = tabControl3.TabPages[tabControl3.TabPages.Count - 1];
                return;
            }
            else if ((dh.matrixs == null || dh.matrixs.Count == 0) && dh.criteriasComparison[dh.criteriasComparison.Count - 1][0].Key != dh.criterias[dh.criterias.Count - 1][0] && dh.criteriasComparison.Count == (AHP.levels - 1))
            {
                TabCompAltShowFirst();
                tabControl1.SelectedTab = tabPage5;
                tabControl3.SelectedTab = tabControl4.TabPages[0];
                return;
            }

            if (tabControl4.TabPages.Count == 0 && tabControl3.TabPages.Count == (AHP.criterias_q.Sum() - AHP.criterias_q[AHP.criterias_q.Length - 1] + 1))
            {
                TabCompAltShowFirst();
            }
            int count = (dh.matrixs == null || dh.matrixs.Count == 0) ? dh.criteriasComparison[dh.criteriasComparison.Count - 1].Count : dh.matrixs.Count;

            for (int i = 0; i < count; i++)
            {
                if (i != 0)
                {
                    curCriteria = dh.criterias[dh.criterias.Count - 1][i];
                    tabp        = new TabPage();
                    tabControl4.TabPages.Add(tabp);
                    TabCompAltShow(ref tabp);
                }
                string[,] matrix = (dh.matrixs == null || dh.matrixs.Count == 0) ? dh.criteriasComparison[dh.criteriasComparison.Count - 1][i].Value : dh.matrixs[i].Value;
                for (int k = 0; k < matrix.GetLength(0) - 1; k++)
                {
                    for (int s = k + 1; s < matrix.GetLength(1); s++)
                    {
                        tboxes[s, k].Text = matrix[k, s];
                    }
                }
                if (i == 0)
                {
                    TabHandle.FindButton(tabControl4.TabPages[0]).Visible = false;
                    TabHandle.MakeReadOnly(tabControl4.TabPages[0]);
                }
                else
                {
                    TabHandle.FindButton(tabp).Visible = false;
                    TabHandle.MakeReadOnly(tabp);
                }
            }
            if (dh.matrixs != null && dh.matrixs.Count != 0)
            {
                bool done = false;
                for (int i = 0; i < dh.criterias[dh.criterias.Count - 1].Length; i++)
                {
                    if (tabControl4.TabPages[tabControl4.TabPages.Count - 1].Name == dh.criterias[dh.criterias.Count - 1][i] && !done)
                    {
                        curCriteria = dh.criterias[dh.criterias.Count - 1][i + 1];
                        tabp        = new TabPage();
                        tabControl4.TabPages.Add(tabp);
                        TabCompAltShow(ref tabp);
                        done = true;
                    }
                }
            }

            if (dh.results == null || dh.results.Count == 0)
            {
                tabControl1.SelectedTab = tabPage5;
                tabControl4.SelectedTab = tabControl4.TabPages[tabControl4.TabPages.Count - 1];
                return;
            }
            TabResultsShow();
            sort.Visible            = radioButton1.Visible = radioButton2.Visible = true;
            tabControl1.SelectedTab = tabPage1;
            tabControl2.SelectedTab = tabPage7;
        }
Esempio n. 8
0
        private void saveDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabPage tab = new TabPage();

            foreach (Control ctrl in tabControl1.SelectedTab.Controls)
            {
                if ((ctrl as TabControl) != null)
                {
                    tab = (ctrl as TabControl).SelectedTab;
                }
            }

            int q = ed_tboxes.GetLength(0);

            double[,] matrix = new double[q, q];
            for (int j = 0; j < q; j++)
            {
                matrix[j, j] = 1;
            }
            int tIndex = 0;

            for (int i = 0; i < q - 1; i++)
            {
                for (int j = i + 1; j < q; j++)
                {
                    double value = ParseValue(ed_tboxes[i, j].Text);

                    /*if (ed_tboxes[i, j].Text.Length == 1)
                     *  value = Convert.ToDouble(ed_tboxes[i, j].Text);
                     * else
                     *  value = 1.0 / Convert.ToDouble(ed_tboxes[i, j].Text[2].ToString());*/
                    matrix[i, j] = value;
                    matrix[j, i] = 1.0 / value;
                    tIndex++;
                }
            }
            for (int i = 0; i < matrixes.Count; i++)
            {
                if (tab.Name == matrixes[i].mainCriteria)
                {
                    matrixes[i] = PairedMatrix.EditPairedMatrix(matrixes[i], matrix);
                }
            }

            for (int i = 0; i < AHP.criteriasComparison.Count; i++)
            {
                for (int j = 0; j < AHP.criteriasComparison[i].Count; j++)
                {
                    if (tab.Name == AHP.criteriasComparison[i][j].mainCriteria)
                    {
                        AHP.criteriasComparison[i][j] = PairedMatrix.EditPairedMatrix(AHP.criteriasComparison[i][j], matrix);
                    }
                }
            }

            if (AHP.results != null)
            {
                AHP.Calculate();
                TabResultsShow();
                t      = null;
                tboxes = null;
            }
            TabHandle.MakeReadOnly(tabControl1.SelectedTab);
            editing = false;
            editDataToolStripMenuItem.Enabled = true;
            saveDataToolStripMenuItem.Enabled = false;
            ed_tboxes = null;
        }
Esempio n. 9
0
        private void btnCompCrit_Click(object sender, EventArgs e)
        {
            int q = AHP.criterias[lvl].Length;

            double[,] matrix = new double[q, q];
            for (int j = 0; j < q; j++)
            {
                matrix[j, j] = 1;
            }
            for (int i = 0; i < q - 1; i++)
            {
                for (int j = i + 1; j < q; j++)
                {
                    double value = ParseValue(tboxes[j, i].Text);

                    /*if (tboxes[j, i].Text.Length == 1)
                     *  value = Convert.ToDouble(tboxes[j, i].Text);
                     * else
                     *  value = Convert.ToDouble(tboxes[j, i].Text.Substring(tboxes[j, i].Text.IndexOf("/") + 1).ToString()) / Convert.ToDouble(tboxes[j, i].Text.Substring(0, tboxes[j, i].Text.IndexOf("/")).ToString());*/
                    matrix[i, j] = value;
                    matrix[j, i] = 1.0 / value;
                    if (matrix[i, j] == 0 || Double.IsInfinity(matrix[i, j]))
                    {
                        MessageBox.Show("Проверьте правильность заполнения полей!");
                        return;
                    }
                }
            }
            matrixes.Add(new PairedMatrix(curCriteria, AHP.criterias[lvl], matrix));
            TabHandle.MakeReadOnly(tabControl1.SelectedTab);

            // если главный критерий на текущем уровне - последний
            if (curCriteria == AHP.problemName || Array.IndexOf(AHP.criterias[lvl - 1], curCriteria) == AHP.criterias[lvl - 1].Length - 1)
            {
                AHP.criteriasComparison.Add(new List <PairedMatrix>(matrixes));
                // перейти к след. уровню критериев или на след. форму
                if (lvl == AHP.levels - 2)
                {
                    matrixes.Clear();
                    TabCompAltShowFirst();
                    tabControl1.SelectedTab = tabPage5;
                }
                else
                {
                    lvl++;
                    curCriteria = AHP.criterias[lvl - 1][0];
                    TabPage tabp = new TabPage();
                    tabControl3.TabPages.Add(tabp);
                    matrixes.Clear();
                    TabCompCritShow(ref tabp);
                    tabControl3.SelectedTab = tabp;
                }
            }
            else
            {
                curCriteria = AHP.criterias[lvl - 1][Array.IndexOf(AHP.criterias[lvl - 1], curCriteria) + 1];
                TabPage tabp = new TabPage();
                tabControl3.TabPages.Add(tabp);
                TabCompCritShow(ref tabp);
                tabControl3.SelectedTab = tabp;
            }
            (sender as Button).Visible = false;
        }