예제 #1
0
 private void RedrawResults(SequenceRenderer renderer)
 {
     renderer.Render();
     resGraph.Tag = renderer.Bmp;
     resGraph.Invalidate();
 }
예제 #2
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            resText.Items.Clear();
            Renderer = new SequenceRenderer(resGraph.Width, resGraph.Height, new Element[] { }, Color.White, Color.White);
            Renderer.RenderCleanGraphic();
            this.Invalidate();

            try
            {
                profile.CheckCorrect();
            }
            catch (ProfileException ex)
            {
                MessageBox.Show(ex.Message, Properties.Resources.frmModuleCaption);
                profile.Select(ex.RowIndex, ex.ColIndex);
                return;
            }

            int[] result;

            try
            {
                result = (cmbMethod.SelectedItem as Method).ProcessMethod(profile.NCandidates, profile.NVoters, profile.GetVoters(), profile.GetVotes(), profile.GetPoints());
            }
            catch (MethodException ex)
            {
                MessageBox.Show(string.Format(Properties.Resources.methodException, ex.ExMethod.Name, ex.Message), Properties.Resources.frmModuleCaption);
                return;
            }

            Element[] candidateSequence = new Element[candidates.Count];
            candidateOrder = new string[candidates.Count];

            for (int i = 0; i < candidates.Count; i++)
            {
                candidateSequence[i] = new Element(result[(int)candidates[i].Tag - 1], candidates[i].Text);
            }

            Renderer = new SequenceRenderer(resGraph.Width, resGraph.Height, candidateSequence, Color.LightGreen, Color.Yellow);
            RedrawResults(Renderer);

            Element tmp;

            for (int i = 1; i < Convert.ToInt32(nmCandidates.Value); i++)
            {
                for (int j = Convert.ToInt32(nmCandidates.Value) - 1; j >= i; j--)
                {
                    if (Convert.ToInt32(candidateSequence[j].Tag) < Convert.ToInt32(candidateSequence[j - 1].Tag))
                    {
                        tmp = candidateSequence[j];
                        candidateSequence[j]     = candidateSequence[j - 1];
                        candidateSequence[j - 1] = tmp;
                    }
                }
            }

            for (int i = 0; i < Convert.ToInt32(nmCandidates.Value); i++)
            {
                resText.Items.Add(candidateSequence[i].Tag.ToString() + ". " + candidateSequence[i].ToString());
                candidateOrder[i] = candidateSequence[i].ToString();
            }
        }