private void InitTaskInstace() { int taskInstanceId = Intent.GetIntExtra("TASK_INSTANCE_ID", 0); if (taskInstanceId != 0) { LinearLayout ll = FindViewById <LinearLayout>(Resource.Id.llTaskInstanceResult); var layoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); TaskInstance taskInstance = DBController.Instance.GetTaskInstance(taskInstanceId); IEnumerable <TaskItem> taskItems = taskInstance.TaskItems; IEnumerable <TaskItem> correctTaskItems = taskInstance.Task.TaskItems; int h = 0; foreach (TaskItem taskItem in taskItems) { TextView textView = new TextView(this); textView.Text = "-------------------------"; textView.LayoutParameters = layoutParameters; ll.AddView(textView); textView = new TextView(this); textView.Text = taskInstance.CheckTaskItem(taskItem) ? "Верно" : "Не верно"; textView.LayoutParameters = layoutParameters; ll.AddView(textView); textView = new TextView(this); textView.Text = h + "." + taskItem.Header; textView.LayoutParameters = layoutParameters; ll.AddView(textView); textView = new TextView(this); textView.Text = "Ваш ответ: " + "[ " + taskItem.ToString() + " ]"; textView.LayoutParameters = layoutParameters; ll.AddView(textView); foreach (TaskItem correctTaskItem in correctTaskItems. Where(x => x.LangItemId == taskItem.LangItemId)) { textView = new TextView(this); textView.Text = "Верный ответ: " + "[ " + correctTaskItem.ToString() + " ]"; textView.LayoutParameters = layoutParameters; ll.AddView(textView); } textView = new TextView(this); textView.Text = "-------------------------"; textView.LayoutParameters = layoutParameters; ll.AddView(textView); h++; } } }
public static void ShowTestList() { Console.WriteLine("******* Список тестов *******"); IEnumerable <Test> tests = DBController.Instance.GetTests(); bool isContinueTest = true; while (isContinueTest) { int seqNoTest = 0; foreach (Test t in tests) { Console.WriteLine(seqNoTest + "." + t.Header + " - " + t.Date.ToString() + " [" + t.CorrectAnswerAmount + "/" + (t.CorrectAnswerAmount + t.IncorrectAnswerAmount).ToString() + "]"); seqNoTest++; } int? indexTest = null; bool isValidTestInput = false; while (!isValidTestInput) { Console.Write("Введите номер теста или q для выхода:"); string input = Console.ReadLine(); if (int.TryParse(input, out int temp)) { if (temp >= 0 && temp < tests.Count()) { isValidTestInput = true; indexTest = temp; } } else if (input == "q") { isContinueTest = false; isValidTestInput = true; } } if (indexTest.HasValue) { bool isContinueTask = true; while (isContinueTask) { Test test = tests.ElementAt(indexTest.Value); IEnumerable <TaskInstance> taskInstances = DBController.Instance.GetTaskInstancesByTestId(test.TestId); int seqNoTask = 0; foreach (TaskInstance taskInstance in taskInstances) { Console.WriteLine(seqNoTask + "." + taskInstance.Task.Text + " [" + taskInstance.CorrectAnswerAmount + "/" + (taskInstance.CorrectAnswerAmount + taskInstance.IncorrectAnswerAmount).ToString() + "]"); seqNoTask++; } int? indexTask = null; bool isValidTaskInput = false; while (!isValidTaskInput) { Console.Write("Введите номер упражнения или q для выхода:"); string input = Console.ReadLine(); if (int.TryParse(input, out int temp)) { if (temp >= 0 && temp < taskInstances.Count()) { indexTask = temp; isValidTaskInput = true; } } else if (input == "q") { isContinueTask = false; isValidTaskInput = true; } } if (indexTask.HasValue) { bool isContinueTaskItem = true; while (isContinueTaskItem) { TaskInstance taskInstance = taskInstances.ElementAt(indexTask.Value); TaskInstance fullTaskInstance = DBController.Instance. GetTaskInstance(taskInstance.TaskInstanceId); IEnumerable <TaskItem> taskItems = fullTaskInstance.TaskItems; IEnumerable <TaskItem> correctTaskItems = fullTaskInstance.Task.TaskItems; int seqNoTaskItem = 0; foreach (TaskItem taskItem in taskItems) { Console.WriteLine("-------------------------"); Console.WriteLine(fullTaskInstance.CheckTaskItem(taskItem) ? "Верно" : "Не верно"); Console.WriteLine(seqNoTaskItem + "." + taskItem.Header); Console.WriteLine("Ваш ответ: " + "[ " + taskItem.ToString() + " ]"); foreach (TaskItem correctTaskItem in correctTaskItems. FirstOrDefault(x => x.LangItemId == taskItem.LangItemId).Children) { Console.WriteLine("Верный ответ: " + "[ " + correctTaskItem.ToString() + " ]"); } Console.WriteLine("-------------------------"); seqNoTaskItem++; } bool isValidTaskItemInput = false; while (!isValidTaskItemInput) { Console.Write("Введите q для выхода:"); string input = Console.ReadLine(); if (input == "q") { isContinueTaskItem = false; isValidTaskItemInput = true; } } } } } } } Console.WriteLine("*********************************"); }