Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Timers;
- namespace Projekt
- {
- class Program
- {
- public static List<string> lista = new List<string>();
- public Timer timer;
- public static string path = @"D:\Dokumenty\programowanie\C#\Projekt\Zapis\odp.txt";
- static void Main(string[] args)
- {
- TworzPlik();
- //List<string> lista = new List<string>();
- string komenda = "";
- int liczba = 0;
- int staraliczba = 0;
- while (liczba != -10)
- {
- Console.WriteLine("Wpisz numer zadania.");
- liczba = Convert.ToInt32(Console.ReadLine());
- if (liczba > staraliczba)
- {
- for (int i = 0; i <= liczba; i++)
- {
- lista.Add("");
- }
- }
- staraliczba = liczba;
- if (liczba != -10)
- {
- Console.WriteLine("Wpisz swoją komendę.");
- komenda = Console.ReadLine();
- if (Odczyt(komenda) == true)
- {
- if (lista.ElementAtOrDefault(liczba) != "")
- lista.RemoveAt(liczba);
- else if (lista.ElementAtOrDefault(liczba) != komenda)
- lista.RemoveAt(liczba);
- lista.Insert(liczba, komenda);
- }
- else
- Console.WriteLine("Zla komenda");
- }
- }
- for (int i= 0;i< lista.Capacity;i++)
- {
- lista.RemoveAll(intem => intem=="");
- }
- //File.WriteAllLines(path, lista);
- Console.ReadKey();
- }
- /*public static void Zapis(List<string> listaS)
- {
- File.WriteAllLines(path, listaS);
- }*/
- public static void TworzPlik()
- {
- if (!File.Exists(path))
- {
- using (StreamWriter ws = File.CreateText(path))
- {
- ws.WriteLine(" ");
- ws.Close();
- }
- }
- else
- {
- using (StreamWriter ws = File.CreateText(path))
- {
- ws.WriteLine(" ");
- ws.Close();
- }
- }
- }
- public void Czas()
- {
- timer = new Timer();
- timer.Tick += new EventHandler(timer_Tick);
- timer.Interval = 3000; // in miliseconds
- timer.Start();
- }
- private void timer_Tick(object sender, EventArgs e)
- {
- File.WriteAllLines(path, lista);
- }
- static bool Odczyt(string zapytanie)
- {
- if (zapytanie.Contains("SELECT") && zapytanie.Contains("FROM"))
- {
- if (zapytanie.Contains("WHERE") || zapytanie.Contains("ORDER BY"))
- {
- string tymczasowe = zapytanie;
- for (dynamic i = 0, nowe = new string[,] { { "SELECT", "1" }, { "FROM", "2" }, { "WHERE", "3" },{"ORDER BY","4" } }; i < nowe.Length / 2; i++)
- tymczasowe = tymczasowe.Replace(nowe[i, 0], nowe[i, 1]);
- string justNumbers = new String(tymczasowe.Where(Char.IsDigit).ToArray());
- bool czyDobrze = Enumerable.SequenceEqual(justNumbers.OrderBy(x => x), justNumbers);
- if (czyDobrze == true)
- return true;
- else
- return false;
- }
- else
- {
- string tymczasowe = zapytanie;
- for (dynamic i = 0, repl = new string[,] { { "SELECT", "1" }, { "FROM", "2" }, { "WHERE", "3" }, { "ORDER BY", "4" } }; i < repl.Length / 2; i++)
- {
- tymczasowe = tymczasowe.Replace(repl[i, 0], repl[i, 1]);
- }
- string justNumbers = new String(tymczasowe.Where(Char.IsDigit).ToArray());
- bool sorted1 = Enumerable.SequenceEqual(justNumbers.OrderBy(x => x), justNumbers);
- if (sorted1 == true)
- return true;
- else
- return false;
- }
- }
- else
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement