Advertisement
Guest User

lab4

a guest
Nov 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4.  
  5. namespace refueling
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         Model model = new Model();
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void label1_Click(object sender, EventArgs e)
  16.         {
  17.             Thread myThread = new Thread(new ThreadStart(Func1));
  18.         }
  19.  
  20.         public static void Func1()
  21.         {
  22.             Model m = new Model();
  23.             m.DoOneIteration();
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             checkBox1.Checked = false;
  29.             checkBox2.Checked = false;
  30.             checkBox3.Checked = false;
  31.  
  32.             textBox2.Clear();
  33.             textBox3.Clear();
  34.             textBox4.Clear();
  35.             textBox6.Clear();
  36.             FlashToTextBox(0, 0, 0, 0);
  37.  
  38.             if (!SetData())
  39.             {
  40.                 return;
  41.             }
  42.  
  43.             for (int i = 0; i < model.GetNumberOfIteration(); i++)
  44.             {
  45.                 model.DoOneIteration();
  46.                 checkBox1.Checked = model.GetCheckBox1();
  47.                 checkBox2.Checked = model.GetCheckBox2();
  48.                 checkBox3.Checked = model.GetCheckBox3();
  49.                 FlashToTextBox(model.GetNumberOfCar(), model.GetCarsGone(), model.GetCarsIn(), i + 1);
  50.             }
  51.         }
  52.        
  53.         private void button2_Click(object sender, EventArgs e){ }
  54.  
  55.         private void radioButton1_CheckedChanged(object sender, EventArgs e){}
  56.  
  57.         private void timer1_Tick(object sender, EventArgs e){}
  58.  
  59.         private void FlashToTextBox(int numOfCar, int carsGone, int carsIn, int numOfIteration)
  60.         {
  61.             textBox4.Text = numOfCar.ToString();
  62.             textBox4.Update();
  63.             textBox2.Text = carsGone.ToString();
  64.             textBox2.Update();
  65.             textBox3.Text = carsIn.ToString();
  66.             textBox3.Update();
  67.             textBox6.Text = numOfIteration.ToString();
  68.             textBox6.Update();
  69.             Thread.Sleep(50);
  70.         }
  71.  
  72.         private bool SetData()
  73.         {
  74.             double dTmp;
  75.             int iTmp;
  76.  
  77.             model.SetNumOfCar(0);
  78.             model.SetCarsGone(0);
  79.             model.SetCarsIn(0);
  80.  
  81.             if (!double.TryParse(textBox5.Text, out dTmp))
  82.             {
  83.                 return false;
  84.             }
  85.             if (dTmp > 1)
  86.             {
  87.                 return false;
  88.             }
  89.             model.SetComingTime(dTmp);
  90.  
  91.             if (!double.TryParse(textBox7.Text, out dTmp))
  92.             {
  93.                 return false;
  94.             }
  95.             if (dTmp > 1)
  96.             {
  97.                 return false;
  98.             }
  99.             model.SetRefuelingTime(dTmp);
  100.  
  101.             if (!int.TryParse(textBox1.Text, out iTmp))
  102.             {
  103.                 return false;
  104.             }
  105.             model.SetNumOfIteration(iTmp);
  106.  
  107.             return true;
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement