示例#1
0
        public static void Main(string[] args)
        {
            List <ConnectionInfo>       Record           = new List <ConnectionInfo>();
            LoadConnectionInfo          ConnectionLoader = new LoadConnectionInfo();
            SaveConnectionInfo          ConnectionSave   = new SaveConnectionInfo();
            RecordList <ConnectionInfo> RecordList       = new RecordList <ConnectionInfo>();

            while (true)
            {
                PrintMenu();
                Int32.TryParse(Console.ReadLine(), out Int32 CaseKey);

                switch (CaseKey)
                {
                case 1:

                    Console.WriteLine("Read from file");
                    String FileName = Console.ReadLine() + ".txt";
                    Record = ConnectionLoader.LoadText(FileName, true).Result;
                    ShowMessagePressAnyKey();
                    break;

                case 2:

                    Console.WriteLine("Display inactive cases first");
                    Record.Sort();
                    RecordList <ConnectionInfo> .PrintRecord(Record);

                    ShowMessagePressAnyKey();
                    break;

                case 3:

                    Console.WriteLine("Find Record By Text");
                    string TextForSearchRecords = Console.ReadLine();
                    RecordList <ConnectionInfo> .PrintRecord(Record.FindAll(x => x.Text.Contains(TextForSearchRecords)));

                    ShowMessagePressAnyKey();
                    break;

                case 4:

                    Console.WriteLine("Delete Record By Id");
                    Int32.TryParse(Console.ReadLine(), out Int32 DeleteById);
                    Record.RemoveAll(x => (x.Id == DeleteById));
                    ShowMessagePressAnyKey();
                    break;

                case 5:

                    Console.WriteLine("Edit Text Record By Id");
                    Int32.TryParse(Console.ReadLine(), out Int32 IdForSearchRecords);
                    Record.Find(x => x.Id == IdForSearchRecords).Text = Console.ReadLine();
                    ShowMessagePressAnyKey();

                    break;

                case 6:

                    Console.WriteLine("Save Record in File");
                    String FileNameWhereToSaveRecord = Console.ReadLine() + ".txt";
                    ConnectionSave.SaveFileWithRecords(Record, FileNameWhereToSaveRecord);
                    ShowMessagePressAnyKey();

                    break;

                case 7:

                    Console.WriteLine("Clear List");
                    Record.Clear();
                    ShowMessagePressAnyKey();
                    break;

                case 8:

                    Console.WriteLine("Show Record");
                    RecordList <ConnectionInfo> .PrintRecord(Record);

                    ShowMessagePressAnyKey();

                    break;

                case 9:

                    Console.WriteLine("Mark entry completed / failed By Id");
                    Int32.TryParse(Console.ReadLine(), out Int32 IdForSearchRecordsToggleActive);
                    Int32 IndexForChangeActive = Record.FindIndex(x => x.Id == IdForSearchRecordsToggleActive);
                    Record[IndexForChangeActive].Active = !Record[IndexForChangeActive].Active;
                    ShowMessagePressAnyKey();

                    break;

                case 10:

                    Console.WriteLine("Add new Record");
                    Record.Add(new ConnectionInfo(id: Record.Count + 1, text: Console.ReadLine(), false));
                    ShowMessagePressAnyKey();
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Error 404");
                    Environment.Exit(0);
                    break;
                }
            }
        }