Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Globalization;
- using System.IO;
- namespace Tapahtumat
- {
- class Program
- {
- public static void Main(string[] args)
- {
- //string valinta;
- string tiedosto = "tapahtumat.txt";
- string aika;
- string tapahtuma;
- bool lopetus = false;
- while (lopetus!=true)
- {
- switch (LueValinta())
- {
- case "l":
- {
- aika = DateTime.Now.ToString(CultureInfo.GetCultureInfo("fi-FI"));
- tapahtuma = LueTapahtuma();
- TallennaTapahtuma(tiedosto, aika, tapahtuma);
- }
- break;
- case "t":
- TulostaTapahtumat(tiedosto);
- break;
- case "p":
- PoistaTapahtumat(tiedosto);
- break;
- case "":
- lopetus = true;
- break;
- default:
- break;
- }
- }
- }
- public static string LueValinta()
- {
- string valinta;
- Console.Write("Anna valintasi: ");
- valinta = Console.ReadLine();
- return valinta;
- }
- public static string LueTapahtuma()
- {
- string tapahtuma;
- Console.Write("Anna tapahtumarivi: ");
- tapahtuma = Console.ReadLine();
- return tapahtuma;
- }
- public static void TallennaTapahtuma(string tiedosto, string aika, string tapahtuma)
- {
- StreamWriter fout;
- string rivi;
- fout = File.AppendText(tiedosto);
- rivi = aika + ": " + tapahtuma;
- fout.WriteLine(rivi);
- fout.Close();
- }
- public static void PoistaTapahtumat(string tiedosto)
- {
- File.WriteAllText(tiedosto, "");
- }
- public static void TulostaTapahtumat(string tiedosto)
- {
- Console.Write(File.ReadAllText(tiedosto));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement