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.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- /// <summary>
- /// This class is used for loading data from the GUI
- /// </summary>
- public partial class Form1 : Form
- {
- #region Variables & instations
- public Date cDate = new Date();
- public Station cStation = new Station();
- public LoadDocuments load = new LoadDocuments();
- public Updating updateGUI; // = new Updating();
- private string number = "";
- public string firstLine;
- public string lastLine;
- #endregion
- /// <summary>
- /// The constructor of the form
- /// </summary>
- public Form1()
- {
- InitializeComponent();
- StationComboBox.SelectedIndex = 0;
- FindLastDatum();
- }
- /// <summary>
- /// Searching the first + last datum
- /// </summary>
- private void FindLastDatum()
- {
- string station = StationComboBox.SelectedItem.ToString();
- if (station == "Den Helder")
- station = station.Remove(3, 1);
- if (station == "De Bilt")
- station = station.Remove(2, 1);
- switch(station)
- {
- case "Vlissingen":
- number = "310";
- break;
- case "Maastricht":
- number = "380";
- break;
- case "Eelde":
- number = "280";
- break;
- case "DenHelder":
- number = "235";
- break;
- case "DeBilt":
- number = "260";
- break;
- }
- string search = number + ",";
- string line;
- bool first = false;
- try
- {
- //MessageBox.Show("in try");
- using (StreamReader sr = new StreamReader(@"C:\Users\geoffrey\Desktop\school\Leerjaar 2\C#\HoofdStuk 18\Steden\" + station + ".txt"))
- {
- //MessageBox.Show("in using");
- while ((line = sr.ReadLine()) != null)
- {
- line = line.Trim();
- //MessageBox.Show(search + " " + line);
- if (line.StartsWith(search) && !first)
- {
- //MessageBox.Show("in the if " + search);
- firstLine = line;
- //MessageBox.Show(foundLine);
- first = true;
- }
- if(line.StartsWith(search))
- {
- lastLine = line;
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("fout: " + ex.Message);
- }
- string beginDate = firstLine.Substring(4, 8);
- string endDate = lastLine.Substring(4, 8);
- DateTime Begin = new DateTime(Convert.ToInt32(beginDate.Substring(0,4)),Convert.ToInt32(beginDate.Substring(4,2)),Convert.ToInt32(beginDate.Substring(6,2)));
- DateTime end = new DateTime(Convert.ToInt32(endDate.Substring(0, 4)),Convert.ToInt32(endDate.Substring(4, 2)),Convert.ToInt32(endDate.Substring(6, 2)));
- dateTime.MinDate = Begin;
- dateTime.MaxDate = end;
- dateTime.Value = end;
- //MessageBox.Show(Begin + "begindate || enddate" + end);
- }
- /// <summary>
- /// updating the GUI
- /// </summary>
- private void UpdateGUI()
- {
- if (cDate._Date == null)
- {
- string date = dateTime.Value.Year.ToString();
- if (dateTime.Value.Month.ToString().Length < 2)
- date += "0" + dateTime.Value.Month.ToString();
- else
- date += dateTime.Value.Month.ToString();
- if (dateTime.Value.Day.ToString().Length < 2)
- date += "0" + dateTime.Value.Day;
- else
- date += dateTime.Value.Day;
- cDate._Date = date;
- }
- load.StartLoading(cStation._Station, cDate._Date);
- if (load.isLoaded)
- LoadToGUI(load.data);
- //first load the data
- //MessageBox.Show(load.data.Count.ToString());
- if (load.data[2].ToString() == " " && load.isLoaded)
- load.LoadingImage(361, Wind);
- else
- load.LoadingImage(Convert.ToInt32(load.data[2]), Wind);
- }
- /// <summary>
- /// updating the data from the GUI
- /// </summary>
- private void UpdateGegevens_Click(object sender, EventArgs e)
- {
- load.newData[14] = tMaxTX.Text; //data[14];
- load.newData[11] = tGemTG.Text; //data[11];
- load.newData[12] = tMinTN.Text; //data[12];
- load.newData[18] = zDuurSQ.Text;//data[18];
- load.newData[19] = zPercSP.Text;//data[19];
- load.newData[4] = wGemFG.Text; //data[4].;
- load.newData[9] = wMaxFXX.Text;//data[9];
- load.newData[1] = wRichtingDDVEC.Text; //data[2];
- load.newData[21] = nDuurDR.Text; //data[21;
- load.newData[22] = nSomRH.Text; //data[22];
- updateGUI = new Updating(load.newData, StationComboBox.SelectedItem.ToString(),number,cDate._Date);
- }
- /// <summary>
- /// Loading the data to the gui
- /// </summary>
- /// <param name="data">The Data</param>
- public void LoadToGUI(List<string> data)
- {
- #region Loading Data To GUI
- tMaxTX.Text = data[14].Trim();
- tGemTG.Text = data[11].Trim();
- tMinTN.Text = data[12].Trim();
- zDuurSQ.Text = data[18].Trim();
- zPercSP.Text = data[19].Trim();
- wGemFG.Text = data[4].Trim();
- wMaxFXX.Text = data[9].Trim();
- wRichtingDDVEC.Text = data[2].Trim();
- nDuurDR.Text = data[21].Trim();
- nSomRH.Text = data[22].Trim();
- #endregion
- }
- /// <summary>
- /// This Methode setting
- /// </summary>
- private void DateTime_ValueChanged(object sender, EventArgs e)
- {
- string date = dateTime.Value.Year.ToString();
- if (dateTime.Value.Month.ToString().Length < 2)
- date += "0" + dateTime.Value.Month.ToString();
- else
- date += dateTime.Value.Month.ToString();
- if (dateTime.Value.Day.ToString().Length < 2)
- date += "0" + dateTime.Value.Day;
- else
- date += dateTime.Value.Day;
- //MessageBox.Show(date);
- cDate._Date = date;
- UpdateGUI();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void StationComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- cStation._Station = StationComboBox.SelectedItem.ToString();
- UpdateGUI();
- FindLastDatum();
- }
- /// <summary>
- /// this Methode is gonna be used for making the HTML Document
- /// </summary>
- private void OpslaanHTML_Click(object sender, EventArgs e)
- {
- if (load.data == null)
- MessageBox.Show("fout geen gegevens");
- MakingHtmlDoc Html = new MakingHtmlDoc(load.data, StationComboBox.SelectedItem.ToString(), cDate._Date);
- }
- }
- #region class Date and Station
- /// <summary>
- /// this class is used for setting the String date
- /// </summary>
- public class Date : LoadDocuments
- {
- public string _Date
- {
- get;
- set;
- }
- }
- /// <summary>
- /// this class is used for setting the String station
- /// </summary>
- public class Station : LoadDocuments
- {
- public string _Station
- {
- get;
- set;
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement