Esempio n. 1
0
        private async void button1_Click_1(object sender, EventArgs e)
        {
            if (button1.Text == "Generate")
            {
                size = Int32.Parse(textBox1.Text);
                int[]       at   = new int[size];
                int[]       bt   = new int[size];
                int[]       st   = new int[size + 1];
                int[]       ps   = new int[size];
                IList <int> stp  = new List <int>();
                IList <int> psp  = new List <int>();
                int[]       prio = new int[size];
                process_no = 1;
                foreach (Control c in tableLayoutPanel2.Controls)
                {
                    if (c is TextBox)
                    {
                        TextBox txt = (TextBox)c;
                        if (String.IsNullOrEmpty(txt.Text))
                        {
                            MessageBox.Show("Please fill all the fields");
                            return;
                        }
                        else if (!decimal.TryParse(txt.Text, out d))
                        {
                            MessageBox.Show("Please enter numbers only");
                            return;
                        }
                        else
                        {
                            if (!int.TryParse(txt.Text, out time))
                            {
                                MessageBox.Show("Please enter integer value");
                                return;
                            }
                            else if (Int32.Parse(txt.Text) < 0)
                            {
                                MessageBox.Show("Please enter a positive value");
                                return;
                            }
                        }
                        ps[process_no - 1] = process_no;
                        if (tableLayoutPanel2.GetColumn(c) == 0)
                        {
                            at[process_no - 1] = Int32.Parse(txt.Text);
                        }
                        else if (tableLayoutPanel2.GetColumn(c) == 1)
                        {
                            if (Int32.Parse(txt.Text) == 0)
                            {
                                MessageBox.Show("Burst should be bigger than zero");
                                return;
                            }
                            bt[process_no - 1] = Int32.Parse(txt.Text);
                            process_no++;
                        }
                    }
                }
                if (scheduler == "FCFS")
                {
                    FCFS.averageTime(ps, size, bt, at, ref averageWT, ref averageTAT);
                    FCFS.GanttView(size, at, bt, ps, stp, psp);
                }
                else if (scheduler == "SJF")
                {
                    if (radioButton1.Checked)   //Preemptive
                    {
                        SJF.sjf_prmptive(stp, psp, size, at, bt, ps);
                    }
                    else if (radioButton2.Checked)  // Non Preemptive
                    {
                        SJF.sjf_nonprmptive(stp, psp, size, at, bt, ps);
                    }
                }
                else if (scheduler == "PRIORITY")
                {
                    for (int i = 1; i < tableLayoutPanel3.Controls.Count; i++)
                    {
                        if (String.IsNullOrEmpty(tableLayoutPanel3.Controls[i].Text))
                        {
                            MessageBox.Show("Please fill priority field");
                            return;
                        }
                        else if (!decimal.TryParse(tableLayoutPanel3.Controls[i].Text, out d))
                        {
                            MessageBox.Show("Please enter numbers only");
                            return;
                        }
                        else
                        {
                            if (!int.TryParse(tableLayoutPanel3.Controls[i].Text, out time))
                            {
                                MessageBox.Show("Please enter integer value");
                                return;
                            }
                            else if (Int32.Parse(tableLayoutPanel3.Controls[i].Text) < 0)
                            {
                                MessageBox.Show("Please enter a positive value");
                                return;
                            }
                        }
                        prio[i - 1] = Int32.Parse(tableLayoutPanel3.Controls[i].Text);
                    }
                    if (radioButton1.Checked)
                    {
                        PRIORITY.PrioritySort(true, size, at, bt, prio, ps, stp, psp);
                    }
                    else if (radioButton2.Checked)
                    {
                        PRIORITY.PrioritySort(false, size, at, bt, prio, ps, stp, psp);
                    }
                }
                else if (scheduler == "ROUND ROBIN")
                {
                    if (String.IsNullOrEmpty(textBox2.Text))
                    {
                        MessageBox.Show("Please enter time slice");
                        return;
                    }
                    else if (!decimal.TryParse(textBox2.Text, out d))
                    {
                        MessageBox.Show("Please enter time slice numbers only");
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(textBox2.Text, out time))
                        {
                            MessageBox.Show("Please enter time slice integer value");
                            return;
                        }
                        else if (Int32.Parse(textBox2.Text) <= 0)
                        {
                            MessageBox.Show("Please enter time slice a positive non-zero value");
                            return;
                        }
                    }

                    Quantum = Int32.Parse(textBox2.Text);

                    ROUND_ROBIN.RobinSort(Quantum, size, at, bt, ps, stp, psp);
                }
                averageWT       = TIME.avgWaiting(size, at, bt, stp, psp);
                averageTAT      = TIME.avgTurnAround(size, at, stp, psp);
                button1.Text    = "Clear";
                label7.Visible  = true;
                label9.Visible  = true;
                label10.Visible = true;
                label11.Visible = true;
                string str;
                var    result = MessageBox.Show("Run Animated Show?", "Confirm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result != DialogResult.Cancel)
                {
                    // user clicked yes
                    stop = false;
                    for (int i = 0; i <= psp.Count; i++)
                    {
                        str = stp[i].ToString();
                        var Label1 = new Label {
                            BackColor = Color.White, Text = str, AutoSize = true
                        };
                        tableLayoutPanel4.Controls.Add(Label1, i /* Column Index */, 1 /* Row index */);
                        if (i != psp.Count)
                        {
                            int pad    = 10 * (stp[i + 1] - stp[i]);
                            var Label2 = new Label {
                                BackColor = Color.Orange, AutoSize = true
                            };
                            Label2.Font = new Font("Arial", 12, FontStyle.Bold);
                            if (psp[i] == 0)
                            {
                                Label2.Text = "IDLE";
                                tableLayoutPanel4.Controls.Add(Label2, i /* Column Index */, 0 /* Row index */);
                            }
                            else
                            {
                                Label2.Text = "Process " + psp[i];
                                tableLayoutPanel4.Controls.Add(Label2, i /* Column Index */, 0 /* Row index */);
                            }
                            if (result == DialogResult.Yes)
                            {
                                duration = 0;
                                while (duration <= pad)
                                {
                                    await Task.Delay(78);

                                    if (stop)
                                    {
                                        return;
                                    }
                                    duration++;
                                    Label2.Padding = new Padding(duration, 0, duration, 0);
                                }
                            }
                            else
                            {
                                Label2.Padding = new Padding(pad, 0, pad, 0);
                            }
                        }
                    }
                    label10.Text = averageWT.ToString();
                    label11.Text = averageTAT.ToString();
                }
                else
                {
                    button1.Text = "Generate";
                }
            }
            else if (button1.Text == "Clear")
            {
                stop         = true;
                button1.Text = "Generate";
                label10.Text = "";
                label11.Text = "";
                tableLayoutPanel4.Controls.Clear();
            }
        }
Esempio n. 2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (button1.Text == "Generate")
            {
                if (comboBox1.SelectedItem == null)
                {
                    MessageBox.Show("Please select a scheduler");
                    return;
                }
                else if (String.IsNullOrEmpty(textBox1.Text))
                {
                    MessageBox.Show("Please enter no. of processes");
                    return;
                }
                else if (tableLayoutPanel2.Controls.Count == 2)
                {
                    MessageBox.Show("Please customize the scheduler");
                    return;
                }
                size = Int32.Parse(textBox1.Text);
                int[]          at   = new int[size];
                int[]          bt   = new int[size];
                int[]          st   = new int[size + 1];
                int[]          ps   = new int[size];
                IList <int>    stp  = new List <int>();
                IList <int>    psp  = new List <int>();
                List <process> arr  = new List <process>();
                int[]          prio = new int[size];
                foreach (Control c in tableLayoutPanel2.Controls)
                {
                    if (c is TextBox)
                    {
                        TextBox txt = (TextBox)c;
                        if (String.IsNullOrEmpty(txt.Text))
                        {
                            process_no = 1;
                            MessageBox.Show("Please fill all the fields");
                            return;
                        }
                        else if (!int.TryParse(txt.Text, out time))
                        {
                            process_no = 1;
                            MessageBox.Show("Please enter numbers only");
                            return;
                        }
                        else
                        {
                            ps[process_no - 1] = process_no;
                            if (tableLayoutPanel2.GetColumn(c) == 0)
                            {
                                at[process_no - 1] = Int32.Parse(txt.Text);
                            }
                            else if (tableLayoutPanel2.GetColumn(c) == 1)
                            {
                                bt[process_no - 1] = Int32.Parse(txt.Text);
                                process_no++;
                            }
                        }
                    }
                }
                if (scheduler == "FCFS")
                {
                    FCFS.averageTime(ps, size, bt, at, ref averageWT, ref averageTAT);
                    label10.Text = averageWT.ToString();
                    label11.Text = averageTAT.ToString();
                    FCFS.GanttView(size, at, bt, ps, stp, psp);
                }
                else if (scheduler == "SJF")
                {
                    // hna ya Sisy
                    if (radioButton1.Checked)   //Preemptive
                    {
                        SJF.sjf_prmptive(stp, psp, size, at, bt, ps);
                    }
                    else if (radioButton2.Checked)  // Non Preemptive
                    {
                        SJF.sjf_nonprmptive(stp, psp, size, at, bt, ps);
                        // SJF.nonPreemptiveSort(size, at, bt, st, ps);
                    }
                    averageWT  = TIME.avgWaiting(size, at, bt, stp, psp);
                    averageTAT = TIME.avgTurnAround(size, at, stp, psp);
                }
                else if (scheduler == "PRIORITY")
                {
                    for (int i = 1; i < tableLayoutPanel3.Controls.Count; i++)
                    {
                        if (String.IsNullOrEmpty(tableLayoutPanel3.Controls[i].Text))
                        {
                            process_no = 1;
                            MessageBox.Show("Please fill all the fields");
                            return;
                        }
                        else
                        {
                            prio[i - 1] = Int32.Parse(tableLayoutPanel3.Controls[i].Text);
                        }
                    }
                    if (radioButton1.Checked)
                    {
                        PRIORITY.PrioritySort(true, size, at, bt, prio, ps, stp, psp);
                    }
                    else if (radioButton2.Checked)
                    {
                        PRIORITY.PrioritySort(false, size, at, bt, prio, ps, stp, psp);
                    }
                    averageWT  = TIME.avgWaiting(size, at, bt, stp, psp);
                    averageTAT = TIME.avgTurnAround(size, at, stp, psp);
                }
                else if (scheduler == "ROUND ROBIN")
                {
                    if (String.IsNullOrEmpty(textBox2.Text))
                    {
                        process_no = 1;
                        MessageBox.Show("Please enter time slice");
                        return;
                    }
                    else if (!int.TryParse(textBox2.Text, out time))
                    {
                        process_no = 1;
                        MessageBox.Show("Please enter numbers only");
                        return;
                    }

                    Quantum = Int32.Parse(textBox2.Text);
                    ROUND_ROBIN.averagetime(size, at, bt, ps, Quantum, ref averageWT, ref averageTAT, ref psp, ref stp);
                    //ROUND_ROBIN.RobinSort(Quantum, size, at, bt, ps, stp, psp);
                    averageWT  = TIME.avgWaiting(size, at, bt, stp, psp);
                    averageTAT = TIME.avgTurnAround(size, at, stp, psp);
                }
                button1.Text    = "Clear";
                label7.Visible  = true;
                label9.Visible  = true;
                label10.Visible = true;
                label11.Visible = true;
                label10.Text    = averageWT.ToString();
                label11.Text    = averageTAT.ToString();
                string str;
                for (int i = 0; i <= psp.Count; i++)
                {
                    str = stp[i].ToString();
                    var Label1 = new Label {
                        BackColor = Color.White, Text = str, AutoSize = true
                    };
                    tableLayoutPanel4.Controls.Add(Label1, i /* Column Index */, 1 /* Row index */);
                    if (i != psp.Count)
                    {
                        int pad    = 10 * (stp[i + 1] - stp[i]);
                        var Label2 = new Label {
                            BackColor = Color.Orange, AutoSize = true, Padding = new Padding(pad, 0, pad, 0)
                        };
                        Label2.Font = new Font("Arial", 12, FontStyle.Bold);
                        if (psp[i] == 0)
                        {
                            Label2.Text = "IDLE";
                            tableLayoutPanel4.Controls.Add(Label2, i /* Column Index */, 0 /* Row index */);
                        }
                        else
                        {
                            Label2.Text = "Process " + psp[i];
                            tableLayoutPanel4.Controls.Add(Label2, i /* Column Index */, 0 /* Row index */);
                        }
                    }
                }
            }
            else if (button1.Text == "Clear")
            {
                button1.Text = "Generate";
                process_no   = 1;
                //label7.Visible = false;
                //label9.Visible = false;
                label10.Text = "";
                label11.Text = "";
                //label10.Visible = false;
                //label11.Visible = false;
                tableLayoutPanel4.Controls.Clear();
            }
        }