Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.  
  15. /// <summary>
  16. /// This class is used for loading data from the GUI
  17. /// </summary>
  18. public partial class Form1 : Form
  19. {
  20. #region Variables & instations
  21. public Date cDate = new Date();
  22. public Station cStation = new Station();
  23. public LoadDocuments load = new LoadDocuments();
  24. public Updating updateGUI; // = new Updating();
  25. private string number = "";
  26.  
  27. public string firstLine;
  28. public string lastLine;
  29. #endregion
  30.  
  31. /// <summary>
  32. /// The constructor of the form
  33. /// </summary>
  34. public Form1()
  35. {
  36.  
  37. InitializeComponent();
  38. StationComboBox.SelectedIndex = 0;
  39. FindLastDatum();
  40. }
  41.  
  42. /// <summary>
  43. /// Searching the first + last datum
  44. /// </summary>
  45. private void FindLastDatum()
  46. {
  47.  
  48. string station = StationComboBox.SelectedItem.ToString();
  49.  
  50.  
  51. if (station == "Den Helder")
  52. station = station.Remove(3, 1);
  53.  
  54. if (station == "De Bilt")
  55. station = station.Remove(2, 1);
  56.  
  57. switch(station)
  58. {
  59. case "Vlissingen":
  60. number = "310";
  61. break;
  62.  
  63. case "Maastricht":
  64. number = "380";
  65. break;
  66.  
  67. case "Eelde":
  68. number = "280";
  69. break;
  70.  
  71. case "DenHelder":
  72. number = "235";
  73. break;
  74.  
  75. case "DeBilt":
  76. number = "260";
  77. break;
  78. }
  79. string search = number + ",";
  80. string line;
  81. bool first = false;
  82.  
  83. try
  84. {
  85. //MessageBox.Show("in try");
  86. using (StreamReader sr = new StreamReader(@"C:\Users\geoffrey\Desktop\school\Leerjaar 2\C#\HoofdStuk 18\Steden\" + station + ".txt"))
  87. {
  88. //MessageBox.Show("in using");
  89. while ((line = sr.ReadLine()) != null)
  90. {
  91. line = line.Trim();
  92.  
  93. //MessageBox.Show(search + " " + line);
  94. if (line.StartsWith(search) && !first)
  95. {
  96. //MessageBox.Show("in the if " + search);
  97. firstLine = line;
  98. //MessageBox.Show(foundLine);
  99. first = true;
  100. }
  101.  
  102. if(line.StartsWith(search))
  103. {
  104. lastLine = line;
  105.  
  106. }
  107.  
  108. }
  109. }
  110. }
  111. catch (Exception ex)
  112. {
  113. MessageBox.Show("fout: " + ex.Message);
  114. }
  115.  
  116. string beginDate = firstLine.Substring(4, 8);
  117. string endDate = lastLine.Substring(4, 8);
  118. DateTime Begin = new DateTime(Convert.ToInt32(beginDate.Substring(0,4)),Convert.ToInt32(beginDate.Substring(4,2)),Convert.ToInt32(beginDate.Substring(6,2)));
  119. DateTime end = new DateTime(Convert.ToInt32(endDate.Substring(0, 4)),Convert.ToInt32(endDate.Substring(4, 2)),Convert.ToInt32(endDate.Substring(6, 2)));
  120.  
  121. dateTime.MinDate = Begin;
  122. dateTime.MaxDate = end;
  123. dateTime.Value = end;
  124. //MessageBox.Show(Begin + "begindate || enddate" + end);
  125. }
  126.  
  127. /// <summary>
  128. /// updating the GUI
  129. /// </summary>
  130. private void UpdateGUI()
  131. {
  132.  
  133. if (cDate._Date == null)
  134. {
  135. string date = dateTime.Value.Year.ToString();
  136. if (dateTime.Value.Month.ToString().Length < 2)
  137. date += "0" + dateTime.Value.Month.ToString();
  138. else
  139. date += dateTime.Value.Month.ToString();
  140.  
  141. if (dateTime.Value.Day.ToString().Length < 2)
  142. date += "0" + dateTime.Value.Day;
  143. else
  144. date += dateTime.Value.Day;
  145. cDate._Date = date;
  146. }
  147.  
  148.  
  149.  
  150. load.StartLoading(cStation._Station, cDate._Date);
  151.  
  152. if (load.isLoaded)
  153. LoadToGUI(load.data);
  154.  
  155. //first load the data
  156. //MessageBox.Show(load.data.Count.ToString());
  157. if (load.data[2].ToString() == " " && load.isLoaded)
  158. load.LoadingImage(361, Wind);
  159. else
  160. load.LoadingImage(Convert.ToInt32(load.data[2]), Wind);
  161. }
  162.  
  163. /// <summary>
  164. /// updating the data from the GUI
  165. /// </summary>
  166. private void UpdateGegevens_Click(object sender, EventArgs e)
  167. {
  168. load.newData[14] = tMaxTX.Text; //data[14];
  169. load.newData[11] = tGemTG.Text; //data[11];
  170. load.newData[12] = tMinTN.Text; //data[12];
  171. load.newData[18] = zDuurSQ.Text;//data[18];
  172. load.newData[19] = zPercSP.Text;//data[19];
  173. load.newData[4] = wGemFG.Text; //data[4].;
  174. load.newData[9] = wMaxFXX.Text;//data[9];
  175. load.newData[1] = wRichtingDDVEC.Text; //data[2];
  176. load.newData[21] = nDuurDR.Text; //data[21;
  177. load.newData[22] = nSomRH.Text; //data[22];
  178.  
  179. updateGUI = new Updating(load.newData, StationComboBox.SelectedItem.ToString(),number,cDate._Date);
  180.  
  181. }
  182.  
  183. /// <summary>
  184. /// Loading the data to the gui
  185. /// </summary>
  186. /// <param name="data">The Data</param>
  187. public void LoadToGUI(List<string> data)
  188. {
  189. #region Loading Data To GUI
  190. tMaxTX.Text = data[14].Trim();
  191. tGemTG.Text = data[11].Trim();
  192. tMinTN.Text = data[12].Trim();
  193. zDuurSQ.Text = data[18].Trim();
  194. zPercSP.Text = data[19].Trim();
  195. wGemFG.Text = data[4].Trim();
  196. wMaxFXX.Text = data[9].Trim();
  197. wRichtingDDVEC.Text = data[2].Trim();
  198. nDuurDR.Text = data[21].Trim();
  199. nSomRH.Text = data[22].Trim();
  200. #endregion
  201. }
  202.  
  203. /// <summary>
  204. /// This Methode setting
  205. /// </summary>
  206. private void DateTime_ValueChanged(object sender, EventArgs e)
  207. {
  208.  
  209. string date = dateTime.Value.Year.ToString();
  210.  
  211. if (dateTime.Value.Month.ToString().Length < 2)
  212. date += "0" + dateTime.Value.Month.ToString();
  213. else
  214. date += dateTime.Value.Month.ToString();
  215.  
  216. if (dateTime.Value.Day.ToString().Length < 2)
  217. date += "0" + dateTime.Value.Day;
  218. else
  219. date += dateTime.Value.Day;
  220. //MessageBox.Show(date);
  221. cDate._Date = date;
  222. UpdateGUI();
  223.  
  224.  
  225.  
  226. }
  227.  
  228. /// <summary>
  229. ///
  230. /// </summary>
  231. /// <param name="sender"></param>
  232. /// <param name="e"></param>
  233. private void StationComboBox_SelectedIndexChanged(object sender, EventArgs e)
  234. {
  235. cStation._Station = StationComboBox.SelectedItem.ToString();
  236. UpdateGUI();
  237. FindLastDatum();
  238.  
  239. }
  240.  
  241. /// <summary>
  242. /// this Methode is gonna be used for making the HTML Document
  243. /// </summary>
  244. private void OpslaanHTML_Click(object sender, EventArgs e)
  245. {
  246. if (load.data == null)
  247. MessageBox.Show("fout geen gegevens");
  248.  
  249. MakingHtmlDoc Html = new MakingHtmlDoc(load.data, StationComboBox.SelectedItem.ToString(), cDate._Date);
  250. }
  251. }
  252. #region class Date and Station
  253. /// <summary>
  254. /// this class is used for setting the String date
  255. /// </summary>
  256. public class Date : LoadDocuments
  257. {
  258. public string _Date
  259. {
  260. get;
  261. set;
  262. }
  263. }
  264.  
  265. /// <summary>
  266. /// this class is used for setting the String station
  267. /// </summary>
  268. public class Station : LoadDocuments
  269. {
  270. public string _Station
  271. {
  272. get;
  273. set;
  274. }
  275. }
  276. #endregion
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement