Beispiel #1
0
        private void loadStateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Data File|*.dat";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (AHP.problemName != null)
                {
                    DialogResult confirm = MessageBox.Show("Сохранить состояние?", "Загрузка", MessageBoxButtons.YesNoCancel);
                    if (confirm == DialogResult.Yes)
                    {
                        saveStateToolStripMenuItem.PerformClick();
                    }
                    else if (confirm == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                string filename = ofd.FileName;
                string data     = System.IO.File.ReadAllText(filename);
                AHP.Reset();
                DataHandle dh = JsonConvert.DeserializeObject <DataHandle>(data);
                this.Hide();
                this.Controls.Clear();
                Form1 f = new Form1();
                f.NormalizeSize();
                f.Size = this.Size;
                f.Show();
                f.Location = this.Location;
                f.LoadData(dh);
            }
        }
Beispiel #2
0
        private void saveStateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "Data File|*.dat";
            sfd.Title    = "Save state";
            sfd.FileName = "AHP_State.dat";
            if (AHP.problemName != null)
            {
                sfd.FileName = AHP.problemName + ".dat";
            }
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                DataHandle dh = new DataHandle();
                dh.CollectData(tabControl3, tabControl4);
                string data     = JsonConvert.SerializeObject(dh);
                string filename = sfd.FileName;
                System.IO.File.WriteAllText(filename, data);
                MessageBox.Show("Состояние сохранено!");
            }
        }
Beispiel #3
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;
        }