Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Runtime.Serialization;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace Assignment3_CS
- {
- public partial class Form1 : Form
- {
- Weather weather;
- Int32[,] number = new Int32[7,4];
- String[] weatherType = new String[7];
- Int32 index = 0;
- public Form1()
- {
- InitializeComponent();
- weather = new Weather();
- }
- private void generateGraph()
- {
- Graphics graphics = pnlCoolGraph.CreateGraphics();
- graphics.ScaleTransform(1, -1);
- graphics.TranslateTransform(0, -pnlCoolGraph.Height / 2);
- Pen redPen = new Pen(Color.Red, 2);
- for (int from = 0, to = 1; to < 7; from++, to++)
- {
- graphics.DrawLine(redPen, from * (pnlCoolGraph.Width / 6 ), number[from,0], to * (pnlCoolGraph.Width / 6), number[to,0]);
- }
- Pen bluePen = new Pen(Color.Blue, 2);
- for (int from = 0, to = 1; to < 7; from++, to++)
- {
- graphics.DrawLine(bluePen, from * (pnlCoolGraph.Width / 6), number[from, 1], to * (pnlCoolGraph.Width / 6), number[to, 1]);
- }
- Pen greenPen = new Pen(Color.DarkSeaGreen, 2);
- for (int from = 0, to = 1; to < 7; from++, to++)
- {
- graphics.DrawLine(greenPen, from * (pnlCoolGraph.Width / 6), number[from, 2], to * (pnlCoolGraph.Width / 6), number[to, 2]);
- }
- Pen orchidPen = new Pen(Color.DarkOrchid, 2);
- for (int from = 0, to = 1; to < 7; from++, to++)
- {
- graphics.DrawLine(orchidPen, from * (pnlCoolGraph.Width / 6), number[from, 3], to * (pnlCoolGraph.Width / 6), number[to, 3]);
- }
- redPen.Dispose();
- bluePen.Dispose();
- greenPen.Dispose();
- orchidPen.Dispose();
- }
- private void cbSelection_SelectedIndexChanged(object sender, EventArgs e)
- {
- ComboBox cbSelection = (ComboBox)sender;
- Image weathercb = (Image)Properties.Resources.ResourceManager.GetObject(cbSelection.Text);
- if (weathercb != null)
- weatherPic.Image = weathercb;
- }
- private void loadArrays()
- {
- for(int i = 0; i < 7; i++)
- {
- DateTime temp = new DateTime(2015, 5, 25, 7, 47, 0);
- if (i > 0)
- temp = temp.AddDays(i);
- String name = temp.ToString("MMddyyyy") + ".dat";
- name = ".\\..\\..\\weatherDate\\" + name;
- openFileDialog1.FileName = name;
- Stream stream = new FileStream(name, FileMode.Open, FileAccess.Read);
- IFormatter formatter = new BinaryFormatter();
- weather =(Weather)formatter.Deserialize(stream);
- stream.Close();
- number[i, 0] = Convert.ToInt32(weather.txtHigh);
- number[i, 1] = Convert.ToInt32(weather.txtLow);
- number[i, 2] = Convert.ToInt32(weather.txtPrecip);
- number[i, 3] = Convert.ToInt32(weather.txtWind);
- weatherType[i] = weather.cbSelection;
- }
- }
- private void updateDay()
- {
- txtDayHigh.Text = Convert.ToString(number[index, 0]);
- txtDayLow.Text = Convert.ToString(number[index, 1]);
- txtDayPrecip.Text = Convert.ToString(number[index, 2]);
- txtDayWind.Text = Convert.ToString(number[index, 3]);
- String temp = weatherType[index];
- Image weathercb = (Image)Properties.Resources.ResourceManager.GetObject(temp);
- if (weathercb != null)
- weatherPicDay.Image = weathercb;
- }
- private void updatePicture()
- {
- Image image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[0]);
- if (image != null)
- pbDay1.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[1]);
- if (image != null)
- pbDay2.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[2]);
- if (image != null)
- pbDay3.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[3]);
- if (image != null)
- pbDay4.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[4]);
- if (image != null)
- pbDay5.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[5]);
- if (image != null)
- pbDay6.Image = image;
- image = (Image)Properties.Resources.ResourceManager.GetObject(weatherType[6]);
- if (image != null)
- pbDay7.Image = image;
- }
- //private void updateOfWeek()
- //{
- // lblDate.Text = day.dayOfTheWeek;
- //}
- private void btnSave_Click(object sender, EventArgs e)
- {
- String precip;
- String wind;
- String high;
- String low;
- precip = @"\d{2}";
- string testString = txtPrecip.Text;
- Match match = Regex.Match(testString, precip);
- if (txtPrecip.Text == "")
- MessageBox.Show("Please enter a precipitation percentage. Ex. 20");
- wind = @"\d{2}";
- string testString1 = txtWind.Text;
- Match match1 = Regex.Match(testString1, wind);
- if (txtWind.Text == "")
- MessageBox.Show("Please enter a wind speed. Ex. 10");
- high = @"\d{2}";
- string testString2 = txtHigh.Text;
- Match match2 = Regex.Match(testString2, high);
- if (txtHigh.Text == "")
- MessageBox.Show("Please enter a temperature high. Ex. 25");
- low = @"\d{2}";
- string testString3 = txtLow.Text;
- Match match3 = Regex.Match(testString3, low);
- if (txtLow.Text == "")
- MessageBox.Show("Please enter a temperature high. Ex. -10");
- weather.txtWind = txtWind.Text;
- weather.txtPrecip = txtPrecip.Text;
- weather.txtLow = txtLow.Text;
- weather.txtHigh = txtHigh.Text;
- weather.cbSelection = cbSelection.Text;
- saveFileDialog1.InitialDirectory = Path.GetFullPath(".\\..\\..\\weatherDate");
- if (cbSelection.Text != "")
- weather.cbSelection = cbSelection.Text;
- saveFileDialog1.FileName = weatherDate.Value.ToString("MMddyyyy") + ".dat";
- DialogResult save = saveFileDialog1.ShowDialog();
- if (save == DialogResult.OK)
- {
- string nameOfFile = saveFileDialog1.FileName;
- Stream stream = new FileStream(nameOfFile, FileMode.Create, FileAccess.Write);
- IFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, weather);
- stream.Close();
- }
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- openFileDialog1.InitialDirectory = Path.GetFullPath(".\\..\\..\\weatherDate");
- DialogResult open = openFileDialog1.ShowDialog();
- if (open == DialogResult.OK)
- {
- string nameOfFile = openFileDialog1.FileName;
- Stream stream = new FileStream(nameOfFile, FileMode.Open, FileAccess.Read);
- IFormatter formatter = new BinaryFormatter();
- weather = (Weather)formatter.Deserialize(stream);
- stream.Close();
- }
- txtWind.Text = weather.txtWind;
- txtPrecip.Text = weather.txtPrecip;
- txtLow.Text = weather.txtLow;
- txtHigh.Text = weather.txtHigh;
- cbSelection.Text = weather.cbSelection;
- }
- private void tabControlWeek_SelectedIndexChanged(object sender, EventArgs e)
- {
- loadArrays();
- updateDay();
- updatePicture();
- generateGraph();
- }
- private void weatherDate_ValueChanged(object sender, EventArgs e)
- {
- DateTime date = DateTime.Today;
- for (int day = 0; day < 7; day++)
- {
- date = date.AddDays(1);
- }
- String dateString = String.Format("{0:MMddyyyy}", date);
- }
- private void btnPrev_Click(object sender, EventArgs e)
- {
- DateTime date = DateTime.Today;
- if (index > 0)
- {
- index--;
- updateDay();
- }
- }
- private void btnNext_Click(object sender, EventArgs e)
- {
- if (index < 6)
- {
- index++;
- updateDay();
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- txtHigh.Text = "20";
- txtLow.Text = "10";
- txtPrecip.Text = "30";
- txtWind.Text = "27";
- cbSelection.Text = "Sunny";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement