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

📄 addprocess.cs

📁 java csharp program that ask users a input(process arrival time, burst time and priority)
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace CPUScheduling {
    public partial class AddProcess : Form {
        int numProcess = 15;
        Random r = new Random();
        public List<Process> list = new List<Process>();
        public AddProcess() {
            InitializeComponent();
            button2_Click_1(null, null);
        }

        private void button2_Click_1(object sender, EventArgs e) {
            tlp.Controls.Clear();
            
                for (int x = 0; x < numProcess; x++) {
                    Label lb = new Label();
                    lb.Text = "P" + x.ToString();
                    lb.TextAlign = ContentAlignment.BottomRight;
                    tlp.Controls.Add(lb);

                    ComboBox cb = new ComboBox();
                    cb.Items.AddRange(new string[] { "System", "Interactive", "Batch" });
                    cb.SelectedIndex = 0;
                    cb.DropDownStyle = ComboBoxStyle.DropDownList;
                    tlp.Controls.Add(cb);

                    NumericUpDown nu = new NumericUpDown();
                    nu.Minimum = 1;
                    nu.Maximum = 100;
                    nu.Value = x + 1;
                    tlp.Controls.Add(nu);

                    nu = new NumericUpDown();
                    nu.Maximum = 500;
                    nu.Value = x * 10;
                    tlp.Controls.Add(nu);

                    nu = new NumericUpDown();
                    nu.Minimum = 1;
                    tlp.Controls.Add(nu);
                }
           
        }

        private void button1_Click(object sender, EventArgs e) {
            tlp.Controls.Clear();
            for (int x = 0; x < numProcess; x++) {
                Label lb = new Label();
                lb.Text = "P" + x.ToString();
                lb.TextAlign = ContentAlignment.BottomRight;
                tlp.Controls.Add(lb);

                ComboBox cb = new ComboBox();
                cb.Items.AddRange(new string[] { "System", "Interactive", "Batch" });
                cb.SelectedIndex = r.Next(3);
                cb.DropDownStyle = ComboBoxStyle.DropDownList;
                tlp.Controls.Add(cb);

                NumericUpDown nu = new NumericUpDown();
                nu.Minimum = 1;
                nu.Maximum = 100;
                nu.Value = r.Next(99)+1;
                tlp.Controls.Add(nu);

                nu = new NumericUpDown();
                nu.Maximum = 500;
                nu.Value = r.Next(99)+1;
                tlp.Controls.Add(nu);

                nu = new NumericUpDown();
                nu.Minimum = 1;
                nu.Value = r.Next(15) + 1;
                tlp.Controls.Add(nu);
            }
        }

        private void button3_Click(object sender, EventArgs e) {
            for (int x = 0; x < numProcess; x++) {
                Process p = new Process();
                p.PID = tlp.Controls[x*5].Text;
                p.PTYPE = (Processtype)((ComboBox)tlp.Controls[x*5 + 1]).SelectedIndex;
                p.PRIORITY = int.Parse(((NumericUpDown)tlp.Controls[x*5 + 2]).Value.ToString());
                p.AT = int.Parse(((NumericUpDown)tlp.Controls[x*5 + 3]).Value.ToString());
                p.BT = int.Parse(((NumericUpDown)tlp.Controls[x*5 + 4]).Value.ToString());
                list.Add(p);
            }
            this.Close();
        }

        private void bSave_Click(object sender, EventArgs e) {
            sfd.ShowDialog();
            try {
                Stream s = sfd.OpenFile();
                StreamWriter sw = new StreamWriter(s);
                for (int x = 0; x < numProcess; x++) {
                    sw.Write(tlp.Controls[x * 5].Text + ",");
                    sw.Write(((ComboBox)tlp.Controls[x * 5 + 1]).SelectedIndex.ToString() + ",");
                    sw.Write(int.Parse(((NumericUpDown)tlp.Controls[x * 5 + 2]).Value.ToString()) + ",");
                    sw.Write(int.Parse(((NumericUpDown)tlp.Controls[x * 5 + 3]).Value.ToString()) + ",");
                    sw.Write(int.Parse(((NumericUpDown)tlp.Controls[x * 5 + 4]).Value.ToString()) + ",");
                    sw.Write(System.Environment.NewLine);
                }
                sw.Close();
                s.Close();
            } catch { }
        }
    }
}

⌨️ 快捷键说明

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