public static Items Reading() { Items items = new Items(); List<Item> itemsList = new List<Item>(); bool b = true; while (b) { Console.WriteLine("Press (1) to read from *.txt, (2) - DataBase or (3) to Deserialize"); string s = Console.ReadLine(); int command; if (int.TryParse(s, out command)) { switch (command) { case 1: using (StreamReader sr = File.OpenText("output.txt")) { string sRead = ""; List<string> stringItems = new List<string>(); while ((sRead = sr.ReadLine()) != null) { stringItems.Add(sRead); } foreach (string item in stringItems) { items = Items.GetItemsFromString(item); } Console.WriteLine(items); } break; case 2: string db1 = ConfigurationManager.AppSettings["connectionString"]; DataAccessManager daM = new DataAccessManager(db1); items.CurItems = daM.GetItems(); break; case 3: items = Deserialize(); break; default: break; } } bool exit = false; while (!exit) { Console.WriteLine("Press (1) to exit from Writing or (2) to continue"); s = Console.ReadLine(); if (int.TryParse(s, out command)) { switch (command) { case 1: b = false; exit = true; break; case 2: exit = true; break; default: continue; } } } } items.CurItems = itemsList; return items; }
public static void Writing(Items items) { bool b = true; while (b) { Console.WriteLine("Press (1) to write in *.txt, (2) - in DataBase or (3) to Serialize"); string s = Console.ReadLine(); int command; if (int.TryParse(s, out command)) { switch (command) { case 1: using (StreamWriter sw = File.AppendText("output.txt")) { sw.WriteLine(items); } break; case 2: string db1 = ConfigurationManager.AppSettings["connectionString"]; DataAccessManager daM = new DataAccessManager(db1); foreach(Item item in items.CurItems) { daM.InsertItem(item); } break; case 3: Serialize(items); break; default: break; } } bool exit = false; while (!exit) { Console.WriteLine("Press (1) to exit from Writing or (2) to continue"); s = Console.ReadLine(); if (int.TryParse(s, out command)) { switch (command) { case 1: b = false; exit = true; break; case 2: exit = true; break; default: continue; } } } } }