filip710

z1rssv

Mar 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace RSSVLV2Z1
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         private System.Timers.Timer t;
  17.         private string datoteka = "podaci.txt";
  18.         private int kriticnaVrijednost;
  19.         private StreamReader fileStream;
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.             fileStream = new StreamReader(datoteka);
  25.             t = new System.Timers.Timer(1000);
  26.             t.Elapsed += new System.Timers.ElapsedEventHandler(vrijeme);
  27.         }
  28.  
  29.         private void vrijeme(Object s, System.Timers.ElapsedEventArgs e)
  30.         {
  31.             string line;
  32.             int vrijednost;
  33.  
  34.             if (tb_Kriticna.Text != "")
  35.                 int.TryParse(tb_Kriticna.Text, out kriticnaVrijednost);
  36.             else
  37.                 kriticnaVrijednost = int.MaxValue;
  38.  
  39.             if ((line = fileStream.ReadLine()) != null)
  40.             {
  41.                 int.TryParse(line, out vrijednost);
  42.  
  43.                 rtbx_Podaci.Text += line + "\n";
  44.  
  45.                 if (vrijednost > kriticnaVrijednost)
  46.                     lbl_Poruka.Text = String.Format("Pročitana vrijednost {0} je veća od kritične vrijednosti {1}.", vrijednost, kriticnaVrijednost);
  47.             }
  48.         }
  49.  
  50.         private void btn_Izlaz_Click(object sender, EventArgs e)
  51.         {
  52.             Application.Exit();
  53.         }
  54.  
  55.         private void btn_Start_Stop_Click(object sender, EventArgs e)
  56.         {
  57.             if (t.Enabled == false)
  58.             {
  59.                 t.Start();
  60.                 btn_Start_Stop.Text = "Zaustavi";
  61.             }
  62.             else
  63.             {
  64.                 t.Stop();
  65.                 btn_Start_Stop.Text = "Pokreni";
  66.             }
  67.         }
  68.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  69.         {
  70.             fileStream.Close();
  71.         }
  72.     }
  73. }
Add Comment
Please, Sign In to add comment