Смекни!
smekni.com

Автоматизированная обучающая система по дисциплине "Программирование" (стр. 6 из 6)

{

isCorrect = false;

}

}

}

if (isCorrect) correctAnswers.Add(test.CurrentQuestion.QuestionNumber);

if (!test.IsTestEnded)

{

InitQuestionWindow(test.GoToNextQuestion());

}

else

{

EndTest();

}

}

private void EndTest()

{

FileStream testFileStream = new FileStream("data\results.txt", FileMode.Append);

StreamWriter testStreamWriter = new StreamWriter(testFileStream);

testStreamWriter.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\t" + test.TestName + "\t" + userName + ": " + correctAnswers.Count + "/" + test.QuestionsCount);

testStreamWriter.Close();

testFileStream.Close();

DialogResult userDecision = MessageBox.Show("Вашрезультат - " + correctAnswers.Count + "/" + test.QuestionsCount + "\nПерейтиквыборулекций?", "Тестокончен", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (userDecision == System.Windows.Forms.DialogResult.Yes)

{

parentForm.Show();

this.Close();

}

else

{

Environment.Exit(0);

}

}

private void SetChooseLectureMode()

{

questionsGroupBox.Visible = false;

buttonNextQuestion.Visible = false;

textBoxTest.Visible = false;

}

private void TestForm_FormClosing(object sender, FormClosingEventArgs e)

{

if (parentForm.Visible == false)

{

parentForm.Close();

}

}

private void TestForm_Load(object sender, EventArgs e)

{

}

}

}

Кодформырезультатов

namespace Kursach

{

public partial class ResultsForm : Form

{

public ResultsForm()

{

InitializeComponent();

try

{

FileStream fileStream = new FileStream("data\results.txt", FileMode.Open);

StreamReader streamReader = new StreamReader(fileStream);

textBox1.Text = streamReader.ReadToEnd();

this.Select();

streamReader.Close();

fileStream.Close();

}

catch

{

textBox1.Text = "Никто не проходил тесты";

}

}

private void textBox1_TextChanged(object sender, EventArgs e)

{

}

}

}

Кодинформационнойформы

namespace Kursach

{

public partial class InitForm : Form

{

public InitForm()

{

InitializeComponent();

}

public string UserName

{

get { return textBoxName.Text + " " + textBoxSurname.Text; }

}

private void buttonBeginTest_Click(object sender, EventArgs e)

{

DialogResult = System.Windows.Forms.DialogResult.OK;

}

private void InitForm_Load(object sender, EventArgs e)

{

}

}

}