⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 这是我写的并行计算的作业
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            LoggingLib.Impl.Logger.getInstance().addLog(this.textBoxLog1);
            //int[] originalData = new int[] { 89, 45, 23, 12, 34, 0, 55, 9, 112, 6, 20, 345, 123, 45, 13, -9, 234, 7, 1, 39, 63, 6, 131234 };
            //Processor.CreatProcessors(originalData, 4);
            //Processor.StartProcessors();
            //Processor.WaitSortCompleted();
            //int[] sortedData = Processor.SortedDatas;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            if (radioButtonRadom.Checked)
            {
                int[] originalData = new int[arrayLength];
                Random r = new Random();
                for (int i = 0; i < originalData.Length; i++)
                {
                    originalData[i] = r.Next(0 - arrayLength * 2, arrayLength * 2);
                }
                string temp = "The original datas are:" + Environment.NewLine;
                for (int i = 0; i < originalData.Length; i++)
                {
                    temp += originalData[i].ToString() + " ";
                }
                LoggingLib.Impl.Logger.getInstance().debug(temp);

                int p = (int)this.comboBox1.SelectedItem;
                Processor.CreatProcessors(originalData, p);
                Processor.StartProcessors();
                Processor.WaitSortCompleted();
                int[] sortedData = Processor.SortedDatas;

                temp = "The sorted datas are:" + Environment.NewLine;
                for (int i = 0; i < sortedData.Length; i++)
                {
                    temp += sortedData[i].ToString() + " ";
                }
                LoggingLib.Impl.Logger.getInstance().debug(temp);
            }
            else if (radioButtonFile.Checked)
            {
                System.Windows.Forms.MessageBox.Show("对不起,本程序目前还不支持文件输入数据!");
            }
            else if (radioButtonHand.Checked)
            {
                System.Windows.Forms.MessageBox.Show("对不起,本程序目前还不支持手动输入数据!");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请选择一个数据输入方式!");
            }
        }

        private void radioButtonRadom_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonRadom.Checked)
            {
                this.textBoxLength.Enabled = true;
                this.textBoxLength.Focus();
            }
            else
            {
                this.textBoxLength.Enabled = false;
            }
        }

        private void textBoxLength_Validated(object sender, EventArgs e)
        {
                try
                {
                    int length = Convert.ToInt32(textBoxLength.Text);
                    if (length < 4)
                    {
                        System.Windows.Forms.MessageBox.Show("数组长度必须>=3");
                        this.textBoxLength.Focus();
                    }
                    arrayLength = length;
                    int p = (int)Math.Truncate(Math.Sqrt(length));
                    this.comboBox1.Items.Clear();
                    for (int i = 2; i <= p; i++)
                    {
                        this.comboBox1.Items.Add(i);
                    }
                    this.comboBox1.SelectedIndex = this.comboBox1.Items.Count - 1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("请输入一个大于1的整数!");
                    this.textBoxLength.Focus();
                }
 
        }

        private int arrayLength = -1;

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBoxLog1.Clear();
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -