Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Globalization;
  7. using System.IO;
  8.  
  9. namespace Tapahtumat
  10. {
  11. class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. //string valinta;
  16. string tiedosto = "tapahtumat.txt";
  17. string aika;
  18. string tapahtuma;
  19. bool lopetus = false;
  20. while (lopetus!=true)
  21. {
  22. switch (LueValinta())
  23. {
  24. case "l":
  25. {
  26. aika = DateTime.Now.ToString(CultureInfo.GetCultureInfo("fi-FI"));
  27. tapahtuma = LueTapahtuma();
  28. TallennaTapahtuma(tiedosto, aika, tapahtuma);
  29.  
  30. }
  31. break;
  32.  
  33. case "t":
  34. TulostaTapahtumat(tiedosto);
  35. break;
  36.  
  37. case "p":
  38. PoistaTapahtumat(tiedosto);
  39. break;
  40.  
  41. case "":
  42. lopetus = true;
  43. break;
  44.  
  45. default:
  46.  
  47. break;
  48. }
  49. }
  50. }
  51.  
  52. public static string LueValinta()
  53. {
  54. string valinta;
  55. Console.Write("Anna valintasi: ");
  56. valinta = Console.ReadLine();
  57. return valinta;
  58. }
  59.  
  60. public static string LueTapahtuma()
  61. {
  62. string tapahtuma;
  63. Console.Write("Anna tapahtumarivi: ");
  64. tapahtuma = Console.ReadLine();
  65. return tapahtuma;
  66.  
  67. }
  68. public static void TallennaTapahtuma(string tiedosto, string aika, string tapahtuma)
  69. {
  70. StreamWriter fout;
  71. string rivi;
  72. fout = File.AppendText(tiedosto);
  73.  
  74. rivi = aika + ": " + tapahtuma;
  75. fout.WriteLine(rivi);
  76.  
  77. fout.Close();
  78. }
  79. public static void PoistaTapahtumat(string tiedosto)
  80. {
  81. File.WriteAllText(tiedosto, "");
  82. }
  83. public static void TulostaTapahtumat(string tiedosto)
  84. {
  85. Console.Write(File.ReadAllText(tiedosto));
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement