static void InsertActor() { Actor actor = GetActor(); Actor result = database.actors.Create(actor); database.Save(); Console.WriteLine("INSERT"); TablePrinter <Actor> .Print(result); }
static void GetFilmsWhereThereIsNoWord() { Console.Write("str: "); string word = Console.ReadLine(); uint page = 1; uint limit = 10; bool exit = false; do { Console.Clear(); List <Film> films = FilmController.GetFilmsWhereThereIsNoWord(word, page, limit); TablePrinter <Film> .Print(films); Console.WriteLine("1. Prev"); Console.WriteLine("2. Next"); Console.WriteLine("3. Exit."); Console.Write("Сhoose a comm: "); string answer = Console.ReadLine(); switch (answer) { case "1": { if (page != 1) { page--; } break; } case "2": { page++; break; } case "3": { exit = true; break; } default: { break; } } }while (!exit); }
public void Start(DatabaseDialog databaseDialog, int whichDatabase, TableDialog tableDialog, int whichTable) { //Start the Control() method, and set returned value as option int option = Control(); switch (option) { case 0: //If --Print Table-- is selected print the table TablePrinter.Print(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 1: //If --Search in table-- is selected, print table only with content matching the search TableSearcher.Search(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 2: //If --Edit table-- is selected let user select the cell to edit TableEditor.SelectCell(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 3: //If --Add new row-- is selected start adding new row RowAdder.Add(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 4: //If --Add new column-- is selected start adding new column ColumnAdder.Add(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 5: //If --Delete column-- is selected let user select the column to delete ColumnDeleter.SelectColumn(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 6: //If --Delete row-- is selected let user select the row to delete RowDeleter.SelectRow(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 7: //If --Delete table-- is selected start deleting currently selected table TableDeleter.Delete(ConnectionString, ServerType, databaseDialog, whichDatabase, tableDialog, whichTable, this); break; case 8: //If --Return-- is selected return to the tableDialog tableDialog.Start(databaseDialog, whichDatabase, this); break; } }
static void GetActorsWithPagination() { int page = 1; int limit = 10; bool exit = false; do { Console.Clear(); int start = (page * limit) - limit; List <Actor> actors = database.actors.GetAll().OrderBy(x => x.Id).Skip(start).Take(limit).ToList(); TablePrinter <Actor> .Print(actors); Console.WriteLine("1. Prev"); Console.WriteLine("2. Next"); Console.WriteLine("0. Exit."); Console.Write("Сhoose a comm: "); string answer = Console.ReadLine(); switch (answer) { case "1": { if (page != 1) { page--; } break; } case "2": { page++; break; } case "0": { exit = true; break; } default: { break; } } }while (!exit); }
public void Print(TextWriter writer, IReadOnlyCollection <ReplayResource> items, int outputMaxWidth) { var tableBuilder = new TableBuilder(outputMaxWidth); tableBuilder.AddColumn("NAME", items.Select(x => x.Date.ToString("yyyy-MM-dd HH.mm.ss")).ToList()); tableBuilder.AddColumn("CONTEXT", items.Select(x => x.Context).ToList()); tableBuilder.AddColumn("PROCESSED", items.Select(x => x.Processed.ToString()).ToList()); tableBuilder.AddColumn("WINNER", items.Select(x => x.Winner.ToString()).ToList()); tableBuilder.AddColumn("TEAMS", items.Select(x => string.Join(", ", x.Teams)).ToList()); var table = tableBuilder.Build(); TablePrinter.Print(writer, table); }
static void GetActorsWithPagination() { uint page = 1; uint limit = 10; bool exit = false; do { Console.Clear(); List <Actor> actors = ActorController.GetWithPagination(page, limit); TablePrinter <Actor> .Print(actors); Console.WriteLine("1. Prev"); Console.WriteLine("2. Next"); Console.WriteLine("0. Exit."); Console.Write("Сhoose a comm: "); string answer = Console.ReadLine(); switch (answer) { case "1": { if (page != 1) { page--; } break; } case "2": { page++; break; } case "0": { exit = true; break; } default: { break; } } }while (!exit); }
static void GetByRating() { Console.WriteLine("Min: "); string answer = Console.ReadLine(); int min = Int32.Parse(answer); Console.WriteLine("Max: "); answer = Console.ReadLine(); int max = Int32.Parse(answer); List <Film> films = FilmController.GetByRating(true, min, max); TablePrinter <Film> .Print(films); }
static void GetByRating() { Console.WriteLine("Min: "); string answer = Console.ReadLine(); int min = Int32.Parse(answer); Console.WriteLine("Max: "); answer = Console.ReadLine(); int max = Int32.Parse(answer); List <Film> films = database.films.Find(x => x.Rating >= min && x.Rating <= max).ToList(); TablePrinter <Film> .Print(films); }
static void Main(string[] args) { var t = new TablePrinter("Id", "Name", "Age"); string connectionstring = "connectionstring"; SqlConnection connection = new SqlConnection(connectionstring); connection.Open(); string sql = "Select * from Student"; SqlCommand command = new SqlCommand(sql, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { t.AddRow(reader["Id"], reader["Name"], reader["Age"]); } t.Print(); Console.ReadKey(); }
static void GetActorById() { long id = GetId(); if (id < 0) { return; } Actor actor = ActorController.GetById(id); if (actor != null) { TablePrinter <Actor> .Print(actor); } else { Console.WriteLine("NO RECORD"); } }
static void GetGenreById() { long id = GetId(); if (id < 0) { return; } Genre genre = GenreController.GetById(id); if (genre != null) { TablePrinter <Genre> .Print(genre); } else { Console.WriteLine("NO RECORD"); } }
static void GetAllGenresFromFilm() { long id = GetId(); if (id < 0) { return; } List <Genre> actors = FilmController.GetAllGenresById(id); if (actors.Count > 0) { TablePrinter <Genre> .Print(actors); } else { Console.WriteLine("NO Genres"); } }
static void GetFilmById() { long id = GetId(); if (id < 0) { return; } Film film = FilmController.GetById(id); if (film != null) { TablePrinter <Film> .Print(film); } else { Console.WriteLine("NO RECORD"); } }
public void Print(TextWriter writer, IReadOnlyCollection <SchemeResource> items, int outputMaxWidth) { var tableBuilder = new TableBuilder(outputMaxWidth); tableBuilder.AddColumn("NAME", items.Select(x => x.Name).ToList()); tableBuilder.AddColumn("CONTEXT", items.Select(x => x.Context).ToList()); tableBuilder.AddColumn("HEALTH", items.Select(x => x.Details.WormEnergy.ToString()).ToList()); tableBuilder.AddColumn( "TURN-TIME", items.Select(x => GetTurnTime(x.Details.TurnTimeInfinite, x.Details.TurnTime)).ToList()); tableBuilder.AddColumn( "ROUND-TIME", items.Select(x => GetRoundTime(x.Details.RoundTimeMinutes, x.Details.RoundTimeSeconds)).ToList()); tableBuilder.AddColumn("WORM-SELECT", items.Select(x => x.Details.WormSelect.ToString()).ToList()); tableBuilder.AddColumn("WEAPONS", items.Select(x => GetWeaponSummary(x.Details.Weapons)).ToList()); var table = tableBuilder.Build(); TablePrinter.Print(writer, table); }
static void GetActorById() { int id = GetId(); if (id < 0) { return; } Actor actor = database.actors.Get(id); if (actor != null) { TablePrinter <Actor> .Print(actor); } else { Console.WriteLine("NO RECORD"); } }
static void GetGenreById() { int id = GetId(); if (id < 0) { return; } Genre genre = database.genres.Get(id); if (genre != null) { TablePrinter <Genre> .Print(genre); } else { Console.WriteLine("NO RECORD"); } }
private void Select(string parameters) { var isNoRecordsFound = false; parameters = parameters.ToUpperInvariant(); IEnumerable <FileCabinetRecord> selectedRecords = new List <FileCabinetRecord>(); List <string> displayedFieldsCollection; if (this.TrySelectRecordsWithoutProperties(parameters, out displayedFieldsCollection)) { selectedRecords = this.fileCabinetService.GetRecords().ToList(); isNoRecordsFound = !selectedRecords.Any(); } else if (this.TrySelectRecordsWithProperties(parameters, out displayedFieldsCollection, out List <string> propertiesSignList, out List <Tuple <string, object> > propertiesList)) { ReadOnlyCollection <Tuple <string, object> > readonlyPropertyList = new ReadOnlyCollection <Tuple <string, object> >(propertiesList); ReadOnlyCollection <string> readOnlyPropertySignsList = new ReadOnlyCollection <string>(propertiesSignList); SearchProperties searchProperties = new SearchProperties(readonlyPropertyList, readOnlyPropertySignsList); if (!(searchProperties is null)) { selectedRecords = Memoizer.GetMemoizer(this.fileCabinetService).Select(searchProperties); isNoRecordsFound = !selectedRecords.Any(); } } if (selectedRecords.Any()) { TablePrinter.Print(selectedRecords.OrderBy(record => record.Id), displayedFieldsCollection); Console.WriteLine(); return; } else if (isNoRecordsFound) { Console.WriteLine("Records with this criteria not found."); Console.WriteLine(); return; } Console.WriteLine(HintMessage); Console.WriteLine(); }
static void GetFilmById() { int id = GetId(); if (id < 0) { return; } Film film = database.films.Get(id); if (film != null) { TablePrinter <Film> .Print(film); } else { Console.WriteLine("NO RECORD"); } }
static void DeleteActor() { int id = GetId(); if (id < 0) { return; } Actor result = database.actors.Delete(id); database.Save(); if (result != null) { Console.WriteLine("DELETE"); TablePrinter <Actor> .Print(result); } else { Console.WriteLine("NO RECORD"); } }
static void DeleteGenre() { int id = GetId(); if (id < 0) { return; } Genre genre = database.genres.Delete(id); database.Save(); if (genre != null) { Console.WriteLine("DELETE"); TablePrinter <Genre> .Print(genre); } else { Console.WriteLine("NO RECORD"); } }
static void DeleteFilm() { int id = GetId(); if (id < 0) { return; } Film film = database.films.Delete(id); database.Save(); if (film != null) { Console.WriteLine("DELETE"); TablePrinter <Film> .Print(film); } else { Console.WriteLine("NO RECORD"); } }
public void Print() { /* Test for table output to console */ using (StringWriter stringWriter = new StringWriter()) { Console.SetOut(stringWriter); using (StringReader stringReader = new StringReader(string.Empty)) { Console.SetIn(stringReader); List <int> primeNumbers = new List <int> { 2, 3, 5 }; TablePrinter.Print(primeNumbers); var expectedOutput = "\t2\t3\t5\t" + Environment.NewLine + "2\t4\t6\t10\t" + Environment.NewLine + "3\t6\t9\t15\t" + Environment.NewLine + "5\t10\t15\t25\t" + Environment.NewLine; Assert.AreEqual <string>(expectedOutput, stringWriter.ToString()); } } }
static void Main(string[] args) { CommandoTextWriter.Use(); Console.WriteLine("\n\nDemo of Commando!\n\n".Magenta().Bold()); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine("1. Tables\n\n".Cyan().Bold()); var t = new TablePrinter("Country", "Capital", "Population"); t.AddRow("Sweden", "Stockholm", "~1,3M"); t.AddRow("Norway", "Oslo", "~900k"); t.AddRow("Finland", "Helsinki", "~600k"); t.AddRow("Denmark", "Copenhagen", "~1,3M"); t.Print(); Console.WriteLine("\n\n"); var t2 = new TablePrinter("Country", "Capital", "Population"); t2.AddRow("Sweden", "Stockholm", "~1,3M"); t2.AddRow("Norway", "Oslo", "~900k"); t2.AddRow("Finland", "Helsinki", "~600k"); t2.AddRow("Denmark", "Copenhagen", "~1,3M"); t2.AddFooter("Total", "", "~4,1M"); t2.Print(); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine("\n\n2. Pretty print\n\n".Cyan().Bold()); var p = new PrettyPrinter(); p.Add("Sweden", "Stockholm"); p.Add("Norway", "Oslo"); p.Add("Finland", "Helsinki"); p.Add("Denmark", "Copenhagen"); p.Print(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine("\n\n3. Prompts\n\n".Cyan().Bold()); var prompt = new SelectPrompt("Choose country"); prompt.Add(new PromptItem("Sweden", "SE")); prompt.Add(new PromptItem("Norway", "NO")); prompt.Add(new PromptItem("Finland", "FI")); prompt.Add(new PromptItem("Denmark", "DK")); var item = prompt.Prompt(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine($"You choosed {item.Name}: {item.Value.ToString()}"); new YesNoQuestion("Is this correct?").Prompt(); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); var multiprompt = new MultiSelectPrompt("Choose countries"); multiprompt.Add(new PromptItem("Sweden", "SE")); multiprompt.Add(new PromptItem("Norway", "NO")); multiprompt.Add(new PromptItem("Finland", "FI")); multiprompt.Add(new PromptItem("Denmark", "DK")); var answer = multiprompt.Prompt(); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); var username = new Question("Username", QuestionType.Text).Prompt(); var password = new Question("Password", QuestionType.Password).Prompt(); Console.WriteLine("You choosed:"); foreach (var a in answer) { Console.WriteLine(a.Name); } Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine("\n\n4. Progress bar\n\n".Cyan().Bold()); ProgressBar progressBar = new ProgressBar(); progressBar.Set(10, "Initializing"); Thread.Sleep(2000); progressBar.Set(20, "Downloading..."); Thread.Sleep(1000); progressBar.Set(30); Thread.Sleep(100); progressBar.Set(40); Thread.Sleep(1000); progressBar.Set(50, "Building"); Thread.Sleep(100); progressBar.Set(60); Thread.Sleep(100); progressBar.Set(70); Thread.Sleep(1000); progressBar.Set(80, "Creating databases"); Thread.Sleep(1000); progressBar.Set(90, "Finishing"); Thread.Sleep(2000); progressBar.Set(100); Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); Console.WriteLine("\n\nt. Font styles\n\n".Cyan().Bold()); p = new PrettyPrinter(); p.Add("Zebra", "Zebra".Zebra()); p.Add("Rainbow", "Rainbow".Rainbow()); p.Add("Bold", "Bold".Bold()); p.Add("Italic", "Italic".Italic()); p.Add("Underline", "Underline".Underline()); p.Add("Inverse", "Inverse".Inverse()); p.Add("Red", "Red".Red()); p.Add("White", "White".White()); p.Add("Grey", "Grey".Grey()); p.Add("Black", "Black".Black()); p.Add("Blue", "Blue".Blue()); p.Add("Cyan", "Cyan".Cyan()); p.Add("Green", "Green".Green()); p.Add("Magenta", "Magenta".Magenta()); p.Add("Red", "Red".Red()); p.Add("Yellow", "Yellow".Yellow()); p.Print(); new YesNoQuestion("Quit?").Prompt(); }
static void GetAllFilm() { List <Film> films = FilmController.GetAll(); TablePrinter <Film> .Print(films); }