Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Timers;
  6.  
  7. namespace Projekt
  8. {
  9. class Program
  10. {
  11. public static List<string> lista = new List<string>();
  12. public Timer timer;
  13. public static string path = @"D:\Dokumenty\programowanie\C#\Projekt\Zapis\odp.txt";
  14. static void Main(string[] args)
  15. {
  16. TworzPlik();
  17. //List<string> lista = new List<string>();
  18. string komenda = "";
  19. int liczba = 0;
  20. int staraliczba = 0;
  21. while (liczba != -10)
  22. {
  23. Console.WriteLine("Wpisz numer zadania.");
  24. liczba = Convert.ToInt32(Console.ReadLine());
  25. if (liczba > staraliczba)
  26. {
  27. for (int i = 0; i <= liczba; i++)
  28. {
  29. lista.Add("");
  30. }
  31. }
  32. staraliczba = liczba;
  33. if (liczba != -10)
  34. {
  35. Console.WriteLine("Wpisz swoją komendę.");
  36. komenda = Console.ReadLine();
  37. if (Odczyt(komenda) == true)
  38. {
  39. if (lista.ElementAtOrDefault(liczba) != "")
  40. lista.RemoveAt(liczba);
  41. else if (lista.ElementAtOrDefault(liczba) != komenda)
  42. lista.RemoveAt(liczba);
  43. lista.Insert(liczba, komenda);
  44. }
  45. else
  46. Console.WriteLine("Zla komenda");
  47. }
  48. }
  49. for (int i= 0;i< lista.Capacity;i++)
  50. {
  51. lista.RemoveAll(intem => intem=="");
  52. }
  53. //File.WriteAllLines(path, lista);
  54. Console.ReadKey();
  55. }
  56.  
  57. /*public static void Zapis(List<string> listaS)
  58. {
  59. File.WriteAllLines(path, listaS);
  60. }*/
  61.  
  62. public static void TworzPlik()
  63. {
  64. if (!File.Exists(path))
  65. {
  66. using (StreamWriter ws = File.CreateText(path))
  67. {
  68. ws.WriteLine(" ");
  69. ws.Close();
  70. }
  71. }
  72. else
  73. {
  74. using (StreamWriter ws = File.CreateText(path))
  75. {
  76. ws.WriteLine(" ");
  77. ws.Close();
  78. }
  79. }
  80. }
  81.  
  82. public void Czas()
  83. {
  84. timer = new Timer();
  85. timer.Tick += new EventHandler(timer_Tick);
  86. timer.Interval = 3000; // in miliseconds
  87. timer.Start();
  88. }
  89.  
  90. private void timer_Tick(object sender, EventArgs e)
  91. {
  92. File.WriteAllLines(path, lista);
  93. }
  94.  
  95. static bool Odczyt(string zapytanie)
  96. {
  97. if (zapytanie.Contains("SELECT") && zapytanie.Contains("FROM"))
  98. {
  99. if (zapytanie.Contains("WHERE") || zapytanie.Contains("ORDER BY"))
  100. {
  101. string tymczasowe = zapytanie;
  102. for (dynamic i = 0, nowe = new string[,] { { "SELECT", "1" }, { "FROM", "2" }, { "WHERE", "3" },{"ORDER BY","4" } }; i < nowe.Length / 2; i++)
  103. tymczasowe = tymczasowe.Replace(nowe[i, 0], nowe[i, 1]);
  104. string justNumbers = new String(tymczasowe.Where(Char.IsDigit).ToArray());
  105. bool czyDobrze = Enumerable.SequenceEqual(justNumbers.OrderBy(x => x), justNumbers);
  106. if (czyDobrze == true)
  107. return true;
  108. else
  109. return false;
  110. }
  111. else
  112. {
  113. string tymczasowe = zapytanie;
  114. for (dynamic i = 0, repl = new string[,] { { "SELECT", "1" }, { "FROM", "2" }, { "WHERE", "3" }, { "ORDER BY", "4" } }; i < repl.Length / 2; i++)
  115. {
  116. tymczasowe = tymczasowe.Replace(repl[i, 0], repl[i, 1]);
  117. }
  118. string justNumbers = new String(tymczasowe.Where(Char.IsDigit).ToArray());
  119. bool sorted1 = Enumerable.SequenceEqual(justNumbers.OrderBy(x => x), justNumbers);
  120. if (sorted1 == true)
  121. return true;
  122. else
  123. return false;
  124. }
  125. }
  126. else
  127. return false;
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement