예제 #1
0
        private void btn_to_form5_Click(object sender, EventArgs e)
        {
            bool success = true;
            int  index   = 1;

            foreach (KeyValuePair <int, List <TextBox> > h in holes)
            {
                int location;
                int size;
                int test;

                string s;

                s = (h.Value[0].Text);
                if (s == null || int.TryParse(s, out test) == false)
                {
                    MessageBox.Show("Please enter a valid number\n" + "\t Hole" + index.ToString() + " Location");
                    success = false;
                    break;
                }
                location = int.Parse(s);

                s = (h.Value[1].Text);
                if (s == null || int.TryParse(s, out test) == false || int.Parse(s) == 0)
                {
                    MessageBox.Show("Please enter a valid number\n" + "\t Hole" + index.ToString() + " Size");
                    success = false;
                    break;
                }

                size = int.Parse(s);

                hole nh = new hole(size, location);
                if (nh.get_size() + nh.get_start_location() > memory.get_size())
                {
                    MessageBox.Show("\t      ERROR \n  Hole" + index.ToString() + " is Outside than memory space");
                    return;
                }
                memory.add_hole(nh);
                index++;
            }
            memory.merge_holes();
            if (memory.get_total_empty_space() > memory.get_size())
            {
                MessageBox.Show("\t       ERROR \n Size of Holes is greater than memory size");
                return;
            }
            if (success)
            {
                Form6 frm = new Form6(processes, memory);
                Visible = false;
                frm.ShowDialog();
                Close();
            }
        }
        private void remove_from_memory(object sender, EventArgs e, Panel p, hole h)
        {
            Label lbl = sender as Label;
            int   pos = p.VerticalScroll.Value;

            //p.clear and then change the holes and then merge adjecent holes and the draw again
            p.Controls.Clear();
            if (h.get_color() == Color.Black)
            {
                int index = memory.search_process(h);
                memory.add_hole(h);
                memory.remove_process(index);
                memory.merge_holes();
            }
            else
            {
                int count = memory.get_memory_processes().Count;
                for (int j = 0; j < count; j++)
                {
                    List <hole> t = memory.get_memory_processes();
                    hole        q = t[j];
                    if (q.get_color() == h.get_color())
                    {
                        int index = memory.search_process(q);
                        memory.add_hole(q);
                        memory.remove_process(index);
                        memory.merge_holes();
                        j--;
                        count--;
                    }
                }
            }
            memory_draw();
            p.VerticalScroll.Value = pos;
            //    MessageBox.Show("Process has been removed successfully");
        }