?? input.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 Input : Form
{
TextBox[] names, ats, bts, types;
Random r = new Random();
public List<CPU> list = new List<CPU>();
public Input()
{
InitializeComponent();
names = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9, textBox10};
ats = new TextBox[] { textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17, textBox18, textBox19, textBox20 };
bts = new TextBox[] { textBox21, textBox22, textBox23, textBox24, textBox25, textBox26, textBox27, textBox28, textBox29, textBox30 };
types = new TextBox[] { textBox31, textBox32, textBox33, textBox34, textBox35, textBox36, textBox37, textBox38, textBox39, textBox40};
}
private void button3_Click(object sender, EventArgs e)
{
list.Clear();
for (int i = 0; i < names.Length; i++) {
CPU cpu = new CPU();
cpu.id = names[i].Text;
cpu.at = int.Parse(ats[i].Text);
cpu.bt = int.Parse(bts[i].Text);
cpu.bbt = cpu.bt;
cpu.color = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
switch(types[i].Text.Substring(0,1)) {
case "S":
cpu.type = Processtype.System;
break;
case "I":
cpu.type = Processtype.Interactive;
break;
case "B":
cpu.type = Processtype.Batch;
break;
default:
MessageBox.Show("Invalid Type! See instructions for valid types");
return;
}
list.Add(cpu);
}
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
if (keyboard.Checked) {
for (int i = 0; i < names.Length; i++) {
names[i].Text = "P" + i.ToString();
ats[i].Text = i.ToString();
bts[i].Text = "1";
types[i].Text = ((Processtype)0).ToString().Substring(0, 1);
}
} else if (random.Checked) {
for (int i = 0; i < names.Length; i++) {
names[i].Text = "P" + i.ToString();
ats[i].Text = r.Next(20).ToString();
bts[i].Text = (r.Next(10)+1).ToString();
types[i].Text = ((Processtype)r.Next(3)).ToString().Substring(0, 1);
}
} else if (file.Checked) {
try {
Stream stream = openFileDialog1.OpenFile();
StreamReader streamreader = new StreamReader(stream);
int i = 0;
if (streamreader.ReadLine() == "CPU SCHEDULER DATA FILE") {
while (!streamreader.EndOfStream) {
string[] temp = streamreader.ReadLine().Split('/');
names[i].Text = temp[0];
ats[i].Text = temp[1];
bts[i].Text = temp[2];
types[i].Text = temp[3];
i++;
}
} else {
MessageBox.Show("Invalid Input");
}
} catch { }
}
button3.Enabled = true;
button5.Enabled = true;
}
private void button4_Click(object sender, EventArgs e) {
this.Close();
}
private void button5_Click(object sender, EventArgs e) {
saveFileDialog1.ShowDialog();
try {
Stream stream = saveFileDialog1.OpenFile();
StreamWriter streamwriter = new StreamWriter(stream);
streamwriter.WriteLine("CPU SCHEDULER DATA FILE");
for (int i = 0; i < names.Length; i++) {
streamwriter.Write(names[i].Text + "/" + ats[i].Text + "/" + bts[i].Text + "/" + types[i].Text + System.Environment.NewLine);
}
streamwriter.Close();
stream.Close();
} catch { }
}
private void button1_Click(object sender, EventArgs e) {
openFileDialog1.ShowDialog();
file.Checked = true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -