Beispiel #1
0
 public Counter ConvertToCounter(string line)
 {
     Counter counter = new Counter();
     string tmp = null;
     int k = 0;
     for (int i = 0; i < line.Length; i++)
     {
         if (line[i].ToString().ToLower() != " ")
         tmp += line[i];
         if (line[i].ToString().ToLower() == " ")
         {
             k = i;
             break;
         }
      }
     counter.Yes = Convert.ToInt32(tmp);
     tmp = null;
     for (int i = k + 1; i < line.Length; i++)
     {
         if (line[i].ToString().ToLower() != " ")
         tmp += line[i];
     }
     counter.No = Convert.ToInt32(tmp);
     return counter;
 }
Beispiel #2
0
 public void WriteToFile(Counter counter)
 {
     FileStream fileStream = new FileStream("counter.dat", FileMode.Open, FileAccess.Write);
     BinaryFormatter binaryFormatter = new BinaryFormatter();
     try
     {
         binaryFormatter.Serialize(fileStream, counter);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Відбулася помилка: " + ex.Message, "Помилка",
      MessageBoxButtons.OK, MessageBoxIcon.Warning);
         throw;
     }
     finally
     { fileStream.Close(); }
     
 }
Beispiel #3
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (!Equals("counter.dat", null))
         _counter = _counter.ReadFromFile();
     label1.Text = "Понравилось: " + _counter.Yes;
     label2.Text = "Не понравилось: " + _counter.No;
 }