static void Main(string[] args) { IImporter importer; string command; string argument; if (args.Length != 2) { MessageAndExit("Špatný počet parametrů."); } command = args[0]; argument = args[1]; switch (command) { case "import": string extension = Path.GetExtension(argument).ToLower(); if (extension == ".xml") { //primitive form of dependency injection importer = new XMLImporter(new DataConnectorDB()); importer.Import(argument); } else if (extension == ".xls" || extension == ".xlsx") { importer = new ExcelImporter(new DataConnectorDB()); importer.Import(argument); } else { MessageAndExit("Špatný formát souboru (koncovka)."); } break; case "list": DateTime date; bool isDate = DateTime.TryParse(argument, out date); if (!isDate) { MessageAndExit("Špatný formát data (má být RRRR-MM-DD)."); } new DataConnectorDB().OutputList(date); break; default: break; } Console.WriteLine("Hotovo"); Console.WriteLine("Press Any Key To Continue"); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Select your option"); Console.WriteLine("1: Read from XML"); Console.WriteLine("2: Read from JSON"); var key = Console.ReadKey(false); IEnumerable <Horse> horses = new List <Horse>(); IImporter importer; while (key.Key == ConsoleKey.D1 || key.Key == ConsoleKey.D2) { if (key.Key == ConsoleKey.D1) { importer = new XMLImporter(); horses = importer.Import(); break; } else { importer = new JsonImporter(); horses = importer.Import(); break; } } //Console.WriteLine("Press any key to read from XML file and display horses"); Console.ReadKey(); Console.WriteLine("Now printing horses..."); //Ascending order of horses by price horses = horses.OrderBy(h => h.Price); Console.WriteLine("-----------------------------------------------"); Console.WriteLine("Ordering horses by ascending order of their prices."); Console.WriteLine("Horse Name | Price"); foreach (var horse in horses) { Console.WriteLine(horse.Name + " | " + horse.Price); } Console.WriteLine("Press any key to end"); Console.ReadKey(); }
private void button1_Click(object sender, EventArgs e) { var importer = new XMLImporter(); importer.Import(); }