예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int count = 0;
            int max   = 0;

            foreach (Method m in methods)
            {
                if (m.Match(critCalc()))
                {
                    max++;
                    TestDialog dlg = new TestDialog(m);
                    dlg.setMethod(this);
                    dlg.ShowDialog();
                    if (dlg.getResult() == true)
                    {
                        count++;
                    }
                }
            }

            MessageBox.Show(Properties.Resources.YourResult + count + Properties.Resources.of + max);
        }
예제 #2
0
        public void GenButtons(bool menuGen)
        {
            int i = 1;

            foreach (Button b in BList)
            {
                panel1.Controls.Remove(b);
            }
            BList.Clear();
            foreach (Method m in methods)
            {
                Method method = m;
                if (menuGen)
                {
                    #region Menu Items Generation
                    ToolStripMenuItem b2 = new ToolStripMenuItem();
                    b2.Text = m.GetName();
                    b2.Tag  = method;
                    if (method == meth)
                    {
                        b2.Checked = true;
                    }
                    b2.Click += delegate(object sender, EventArgs e)
                    {
                        if (b2.Checked)
                        {
                            b2.Checked = false;
                            this.meth  = null;
                            GenButtons(false);
                        }
                        else
                        {
                            ToolStripMenuItem ditems = (ToolStripMenuItem)menuStrip1.Items[3];
                            foreach (ToolStripMenuItem it in ditems.DropDownItems)
                            {
                                it.Checked = false;
                            }
                            b2.Checked = true;
                            this.meth  = (Method)b2.Tag;
                            if (meth != null)
                            {
                                if (meth.Match(2))
                                {
                                    radioButton2.Checked = true;
                                }
                                else
                                {
                                    radioButton1.Checked = true;
                                }
                            }
                            for (int eee = 2; eee < 11; eee++)
                            {
                                ((CheckBox)boxes[eee]).Checked = false;
                            }
                            GenButtons(false);
                        }
                    };
                    ToolStripMenuItem item = (ToolStripMenuItem)menuStrip1.Items[3];
                    item.DropDownItems.Add(b2);
                    #endregion
                }
                if (m.Match(critCalc()))
                {
                    #region Button Generation
                    Button b1 = new Button();
                    //if (method == meth)
                    //{
                    //    b1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
                    //}
                    b1.Top    = 15 * i;
                    i        += 2;
                    b1.Left   = 10;
                    b1.Width  = panel1.Width - 20;
                    b1.Text   = m.GetName();
                    b1.Anchor = AnchorStyles.Right | AnchorStyles.Top;
                    b1.Click += delegate(Object s, EventArgs ea)
                    {
                        if (checkBox9.Checked)
                        {
                            TestDialog dlg = new TestDialog(method);
                            dlg.setMethod(this);
                            dlg.ShowDialog();
                        }
                        else
                        {
                            double[,] mat = new double[GvMatr.RowCount, GvMatr.ColumnCount];
                            double[] prob = new double[GVP.ColumnCount];
                            double   alfa, a;
                            foreach (DataGridViewRow row in GvMatr.Rows)
                            {
                                foreach (DataGridViewCell c in row.Cells)
                                {
                                    mat[c.RowIndex, c.ColumnIndex] = System.Double.Parse(c.Value.ToString());
                                }
                            }
                            NormProb();
                            foreach (DataGridViewRow row in GVP.Rows)
                            {
                                foreach (DataGridViewCell c in row.Cells)
                                {
                                    prob[c.ColumnIndex] = System.Double.Parse(c.Value.ToString());
                                }
                            }
                            try
                            {
                                alfa = System.Double.Parse(textBox1.Text);
                            }
                            catch (FormatException)
                            {
                                alfa = 0;
                            }
                            try
                            {
                                a = System.Double.Parse(textBox2.Text);
                            }
                            catch (FormatException)
                            {
                                a = matrMin();
                            }
                            method.Init(mat, prob, alfa, a);
                            int result = method.RunMethod();
                            label5.Text = (result + 1).ToString();
                            Font f = new Font(radioButton1.Font, System.Drawing.FontStyle.Bold);
                            label5.Font = f;
                            for (int j = 0; j < GvMatr.Rows.Count; ++j)
                            {
                                GvMatr.Rows[j].DefaultCellStyle.BackColor             = GvMatr.Rows[j].DefaultCellStyle.SelectionBackColor
                                                                                      = (j == result) ? Color.Yellow : Color.White;
                            }
                            GvMatr[0, result].Selected = true;
                            GvMatr.CurrentCell         = GvMatr[0, result];
                        }
                    };
                    b1.MouseMove += delegate(Object sender, MouseEventArgs e)
                    {
                        Font f = new Font(radioButton1.Font, System.Drawing.FontStyle.Bold);
                        for (int j = 0; j < 11; j++)
                        {
                            if (method.Match((int)Math.Pow(2, j)))
                            {
                                boxes[j].Font = f;
                            }
                        }
                    };
                    b1.MouseLeave += delegate(Object sender, EventArgs e)
                    {
                        Font f = new Font(radioButton1.Font, System.Drawing.FontStyle.Regular);
                        foreach (Control c in boxes)
                        {
                            c.Font = f;
                        }
                    };
                    panel1.Controls.Add(b1);
                    BList.Add(b1);
                    #endregion
                }
            }
        }