2021-09-14 12:31:36 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Tutorial_5
|
|
|
|
|
{
|
|
|
|
|
public partial class CurrentConditionsDisplay : Form, IWeatherObserver, IDisplay
|
|
|
|
|
{
|
|
|
|
|
ISubject subject;
|
2021-09-21 20:07:08 +12:00
|
|
|
|
//WeatherData_old weatherData;
|
2021-09-14 12:31:36 +12:00
|
|
|
|
private void RegisterButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
subject.RegisterObserver(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double temperature = default, humidity = default, pressure = default;
|
2021-09-21 20:07:08 +12:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Push technique
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="temperature"></param>
|
|
|
|
|
/// <param name="humidity"></param>
|
|
|
|
|
/// <param name="pressure"></param>
|
2021-09-14 12:31:36 +12:00
|
|
|
|
public void Update(double temperature, double humidity, double pressure)
|
|
|
|
|
{
|
|
|
|
|
this.temperature = temperature;
|
|
|
|
|
this.humidity = humidity;
|
|
|
|
|
this.pressure = pressure;
|
|
|
|
|
Display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateOther()
|
|
|
|
|
{
|
2021-09-21 20:07:08 +12:00
|
|
|
|
//this.temperature = weatherData.GetTemperature();
|
|
|
|
|
//this.humidity = weatherData.GetHumidity();
|
|
|
|
|
//this.pressure = weatherData.GetPressure();
|
2021-09-14 12:31:36 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Display()
|
|
|
|
|
{
|
|
|
|
|
TemperatureLabel.Text = temperature.ToString() + " ℃";
|
|
|
|
|
HumidityLabel.Text = humidity.ToString() + " %";
|
|
|
|
|
PressureLabel.Text = pressure.ToString() + " kPa";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CurrentConditionsDisplay(ISubject subject)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.subject = subject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|