예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (((int)numericUpDown2.Value < (int)numericUpDown3.Value) && ((int)numericUpDown4.Value < (int)numericUpDown5.Value) && (int)numericUpDown1.Value >= 1)
            {
                if (flag == 0)
                {
                    flag = 1;
                    label7.Text = "Simulating..";
                    label8.Text = "Simulating..";
                    label18.Text = "Simulation in progress..";
                    label7.Refresh();
                    label8.Refresh();
                    label18.Refresh();
                    numericUpDown1.Enabled = false;
                    numericUpDown2.Enabled = false;
                    numericUpDown3.Enabled = false;
                    numericUpDown4.Enabled = false;
                    numericUpDown5.Enabled = false;
                    numericUpDown6.Enabled = false;
                    button1.Enabled = false;
                    CustomerService.WorkingHours = (int)numericUpDown1.Value;
                    CustomerService.MinimumCustomers = (int)numericUpDown2.Value;
                    CustomerService.MaximumCustomers = (int)numericUpDown3.Value;
                    CustomerService.MinimumServingTime = (int)numericUpDown4.Value;
                    CustomerService.MaximumServingTime = (int)numericUpDown5.Value;
                    int SimRate = (int)numericUpDown6.Value;
                    Random Random1 = new Random(DateTime.Now.Second);
                    CustomerService.Number = Random1.Next(CustomerService.MinimumCustomers, CustomerService.MaximumCustomers);
                    label19.Text = Convert.ToString(CustomerService.Number);
                    label19.Refresh();
                    ClientList = new Service[CustomerService.Number];
                    QueueeTest = new Queuee(ClientList);

                    for (int i = 0; i < CustomerService.Number; i++)
                    {
                        ClientList[i] = new Service();
                        CustomerService.ServingTime = Random1.Next(CustomerService.MinimumServingTime, CustomerService.MaximumServingTime);
                        ClientList[i].ServingTime = CustomerService.ServingTime;

                        QueueeTest.enqueue(ClientList[i]);

                    }
                    int temp = CustomerService.Number;
                    for (int i = 0; temp > 0; i++)
                    {
                        CustomerService.TotalServingTime += ClientList[i].ServingTime;
                        temp--;
                    }
                    label19.Text = Convert.ToString(CustomerService.Number);
                    progressBar1.Maximum = CustomerService.Number*600;

                    //Animation starts here.
                    int x, y;
                    for (int j = 0; j < CustomerService.Number; j++)
                    {
                        label22.Text = Convert.ToString(j + 1);
                        label22.Refresh();
                        label24.Text = Convert.ToString(ClientList[j].ServingTime);
                        label24.Refresh();

                        pictureBox2.Location = new Point(314, 285);
                        System.Threading.Thread.Sleep(500);
                        for (int i = 0; i < 600; i++)
                        {
                            progressBar1.Value++;
                            x = pictureBox2.Location.X;
                            y = pictureBox2.Location.Y;

                            if (x == 702)
                            {
                                System.Threading.Thread.Sleep(ClientList[j].ServingTime);
                            }

                            else
                            {

                                pictureBox2.Location = new Point(x + 1, y);
                                System.Threading.Thread.Sleep(10 / SimRate);
                            }

                        }
                    }
                    Serve(ClientList);
                    Display();

                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                MessageBox.Show("Invalid input detected. Please verify the entered values.","Invalid input.");
            }
        }
예제 #2
0
        private void Serve(Service[] _myObjectList)
        {
            ClientList_1 = new Service[CustomerService.Number];

            int i = 0;

            while (i < CustomerService.Number)
            {
                ClientList_1[i] = QueueeTest.dequeue() as Service;
                i++;
            }
        }