You are on page 1of 4

Task 2 ideas

//SOME SAMPLE CODE


public partial class WeatherInput : Form
{

public string filePathPta = Environment.CurrentDirectory + "/" + "Pretoria.txt";


public string filePathDb = Environment.CurrentDirectory + "/" + "Durban.txt";

private void btnReset_Click(object sender, EventArgs e)


{
cBxCity.Text = "Choose a city";
txtBxMinTemp.Clear();
txtBxMaxTemp.Clear();
txtBxPrecip.Clear();
txtBxHumid.Clear();
txtBxWind.Clear();
}

private void btnAccept_Click(object sender, EventArgs e)


{
// assigns the chosen city to the string city
string city = this.cBxCity.GetItemText(this.cBxCity.SelectedItem);
if (city == "Pretoria")
{
using (System.IO.StreamWriter filePta = new System.IO.StreamWriter(filePathPta, true))
{
var tab = "\t";
filePta.WriteLine(DTPInput.Text + tab + txtBxMinTemp.Text + "°C" + tab + txtBxMaxTemp.Text + "°C" + tab +
txtBxPrecip.Text + "%" + tab + txtBxHumid.Text + "%" + tab + txtBxWind.Text + " km/h");
}
}
if (city == "Durban")
{
using (System.IO.StreamWriter fileDb = new System.IO.StreamWriter(filePathDb, true))
{
var tab = "\t";
fileDb.WriteLine(DTPInput.Text + tab + txtBxMinTemp.Text + "°C" + tab + txtBxMaxTemp.Text + "°C" + tab
+ txtBxPrecip.Text + "%" + tab + txtBxHumid.Text + "%" + tab + txtBxWind.Text + " km/h");
}
}

// Clears the boxes


cBxCity.Text = "Choose a city";
txtBxMinTemp.Clear();
txtBxMaxTemp.Clear();
txtBxPrecip.Clear();
txtBxHumid.Clear();
txtBxWind.Clear();

private void BtnCreateFiles_Click(object sender, EventArgs e)


{

if (!File.Exists(filePathPta))
{
File.CreateText(filePathPta);
}

if (!File.Exists(filePathDb))
{
File.CreateText(filePathDb);
}
MessageBox.Show("The .txt files have been created.");
//clicking the create file button more than once will overwrite the old files
}

private void btnGenerate_Click(object sender, EventArgs e)


{

if (ckBxPret.Checked)
{
if (!ckBxCapeT.Checked)
{
rTxtBxCT.Clear();
}
if (!ckBxJohann.Checked)
{
rTxtBxJoBurg.Clear();
}
if (!ckBxDurb.Checked)
{
rTxtBxDb.Clear();
}
rTxtBxPta.Text = File.ReadAllText(@"Pretoria.txt");
}

https://social.msdn.microsoft.com/Forums/en-US/0902ba30-479e-4c2e-bd06-4a03f52e1cdd/quick-way-of-getting-day-and-
month-and-year-from-datetimepicker-component?forum=clr

You might also like