public WindowSolvedTest() { InitializeComponent(); #region re-count int countQuestion = Program.CurrentProject.CountQuestions; int countAnswers = 0; int countTrunessAnswers = 0; int countStudentAnswers = 0; int countTrunessStudentAnswers = 0; foreach (Question selectQ in Program.CurrentProject.Questions) { countAnswers += selectQ.CountAnswers; foreach (Answer selectA in selectQ.Answers) { if (selectA.selectVarStudent) { ++countStudentAnswers; if (selectA.Trueness) { ++countTrunessStudentAnswers; } } if (selectA.Trueness) { ++countTrunessAnswers; } } } #endregion StudentSolvedTest solvedTest = new StudentSolvedTest(Program.CurrentProject.NameProject, Program.CurrentProject.GuidProj) { TimeTest = DateTime.Now, CountQuestions = countQuestion, CountAnswers = countAnswers, CountStudentAnswers = countStudentAnswers, CountTrunessAnswers = countTrunessAnswers, CountTrunessStudentAnswers = countTrunessStudentAnswers }; Program.CurrentAccount.SolvedTests.Add(solvedTest); Program.SaveAccount(Program.PathAccount); stestName.Header = Program.CurrentProject.NameProject; stestCountQuestions.Text = Convert.ToString(countQuestion); stestCountAnswers.Text = Convert.ToString(countAnswers); stestCountStudentAnswers.Text = Convert.ToString(countStudentAnswers); stestCountTrunessAnswers.Text = Convert.ToString(countTrunessAnswers); stestCountTrunessStudentAnswers.Text = Convert.ToString(countTrunessStudentAnswers); // отчистка выбранных студентом вариантов ответа Program.CurrentProject.clearStudentSelectVarAnswer(); }
static bool ParserAccount(string[] readinFile) { //вхождение в блок аккаутна bool inAccount = false; bool inReg = false; string nameAccount = ""; string passwordAccount = ""; Guid guidAccount = Guid.Empty; DateTime dataReg = new DateTime(); //вхождение в блок теста bool inTest = false; StudentSolvedTest currentTest = null; string line = ""; try { foreach (string searchCommand in readinFile) { line += searchCommand; if (line.Contains("<")) { if (line.Contains(">")) { //вырезаем команду из строки line #region delete substring string subStrCommand = line.Substring(line.IndexOf('<'), line.IndexOf('>')); line = line.Remove(line.IndexOf('<'), line.IndexOf('>')); #endregion #region Command string readLine = subStrCommand.Split('<')[1]; string command = readLine.Split('>')[0]; switch (command[0]) { #region command first 'a' case 'a': if (command.Substring(0, 7).CompareTo("account") == 0) { string valStr = command.Split('(')[1]; string nameStudentAndPasswordAndGuid = valStr.Split(')')[0]; nameAccount = nameStudentAndPasswordAndGuid.Split(';')[0]; passwordAccount = nameStudentAndPasswordAndGuid.Split(';')[1]; guidAccount = Guid.Parse(nameStudentAndPasswordAndGuid.Split(';')[2]); CurrentAccount = new StudentAccount(nameAccount, passwordAccount, guidAccount); inAccount = true; } break; #endregion #region command first 'q' case 'r': if ((inAccount) && (command[1] == 'e')) { string valStr = command.Split('(')[1]; dataReg = DateTime.Parse(valStr.Split(')')[0]); CurrentAccount.RegistredData = dataReg; inReg = true; } break; #endregion #region command first 't' case 't': if ((inAccount) && (inReg) && (command[1] == 'e')) { string valStr = command.Split('(')[1]; string nameAndGuidTest = valStr.Split(')')[0]; string nameTest = nameAndGuidTest.Split(';')[0]; Guid guidTest = Guid.Parse(nameAndGuidTest.Split(';')[1]); currentTest = new StudentSolvedTest(nameTest, guidTest); inTest = true; } else if ((inAccount) && (inReg) && (inTest) && (command[1] == 'i')) { string valStr = command.Split('(')[1]; DateTime timeTest = DateTime.Parse(valStr.Split(')')[0]); currentTest.TimeTest = timeTest; } break; #endregion #region command first 'c' case 'c': if ((inAccount) && (inReg) && (inTest) && (command[1] == 'q')) { string valStr = command.Split('(')[1]; int num = Convert.ToInt32(valStr.Split(')')[0]); currentTest.CountQuestions = num; } else if ((inAccount) && (inReg) && (inTest) && (command[1] == 'a')) { #region Result if (command.Substring(0, 3).CompareTo("can") == 0 && command[3] == '(') { string valStr = command.Split('(')[1]; int num = Convert.ToInt32(valStr.Split(')')[0]); currentTest.CountAnswers = num; } else if (command.Substring(0, 4).CompareTo("cans") == 0 && command[4] == '(') { string valStr = command.Split('(')[1]; int num = Convert.ToInt32(valStr.Split(')')[0]); currentTest.CountStudentAnswers = num; } else if (command.Substring(0, 4).CompareTo("cant") == 0 && command[4] == '(') { string valStr = command.Split('(')[1]; int num = Convert.ToInt32(valStr.Split(')')[0]); currentTest.CountTrunessAnswers = num; } else if (command.Substring(0, 5).CompareTo("canst") == 0 && command[5] == '(') { string valStr = command.Split('(')[1]; int num = Convert.ToInt32(valStr.Split(')')[0]); currentTest.CountTrunessStudentAnswers = num; } #endregion } break; #endregion #region command first '/' case '/': if (command[1] == 'a') { inAccount = false; return(true); } else if (command[1] == 't') { CurrentAccount.SolvedTests.Add(currentTest); inTest = false; } break; #endregion } #endregion } else { //добавляем новую строку в line для поиска конца команды '>' continue; } } line = ""; } } catch (Exception) { WindowMsgError error = new WindowMsgError("Ошибка", "Ошибка при чтении файла аккаунта"); error.ShowDialog(); return(false); } WindowMsgError error2 = new WindowMsgError("Ошибка", "Ошибка при чтении файла аккаунта"); error2.ShowDialog(); return(false); }