Поможем написать учебную работу
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.
Тема: Робота з файлами.
Мета роботи. Створити систему для тестування учнів.
Виконання роботи:
Завдання : Створити тест.
Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Артурка_6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value == 100)
{
timer1.Enabled = false;
Form2 f2 = new Form2();
this.Hide();
f2.Show();
}
if (progressBar1.Value < 100)
{
progressBar1.Value += 1;
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
Form 2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Артурка_6
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
string[] a = new string[1000];
private int n = 0;
private void Form2_Load(object sender, EventArgs e)
{
StreamReader streamReader = new StreamReader("1.txt");
string str = "";
while (!streamReader.EndOfStream)
{
a[n] = streamReader.ReadLine();
n++;
}
// listBox1.Items.Add(n.ToString());
}
private int b = 0;
private int v = 0;
private void button2_Click(object sender, EventArgs e)
{
if (v == 0)
{
label1.Text = a[b];
radioButton1.Text = a[b + 1];
radioButton2.Text = a[b + 2];
radioButton3.Text = a[b + 3];
radioButton4.Text = a[b + 4];
b += 6;
v = 1;
button2.Text = "Стоп";
button1.Visible = true;
}else if (v == 1)
{
v = 0;
b = 0;
button1.Visible = false;
button2.Text = "Старт";
label2.Text = numb.ToString();
label3.Text = kil.ToString();
Form6 f6 = new Form6();
f6.label1.Text = label2.Text;
f6.label2.Text = label3.Text;
this.Hide();
f6.Show();
//string srtt = "Кількість питань = " + numb.ToString() + "\nКіл правельних відповідей = "+kil.ToString() + "\nКіл набраних балів = " + (kil*10).ToString();
// MessageBox.Show(srtt, "Результати", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
public int kil = 0;
public int numb = 0;
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true && Convert.ToInt32(a[b - 1]) == 1)
{
kil++;
}
if (radioButton2.Checked == true && Convert.ToInt32(a[b - 1]) == 2)
{
kil++;
}
if (radioButton3.Checked == true && Convert.ToInt32(a[b - 1]) == 3)
{
kil++;
}
if (radioButton4.Checked == true && Convert.ToInt32(a[b - 1]) == 4)
{
kil++;
}
if (a[b] == "")
{
button2_Click(sender, e);
}
;
label1.Text = a[b];
radioButton1.Text = a[b + 1];
radioButton2.Text = a[b + 2];
radioButton3.Text = a[b + 3];
radioButton4.Text = a[b + 4];
b += 6;
numb++;
if (label1.Text == "")
{
button2_Click(sender, e);
}
;
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
private void редагуватиToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
this.Hide();
f3.Show();
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void рекордиToolStripMenuItem_Click(object sender, EventArgs e)
{
Form5 f3 = new Form5();
this.Hide();
f3.Show();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
Form 3:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Артурка_6
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
string str = "";
private void Form3_Load(object sender, EventArgs e)
{
StreamReader streamReader = new StreamReader("pas.txt");
while (!streamReader.EndOfStream)
{
str = streamReader.ReadLine();
}
//MessageBox.Show(str);
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == str)
{
Form4 f4 = new Form4();
this.Hide();
f4.Show();
}
else
{
MessageBox.Show("Не вырний пароль","Помилка",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}
Form 4:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Артурка_6
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private string[] a = new string[1000];
private int n = 0;
private void Form4_Load(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private string[] a1 = new string[1000];
private void button1_Click(object sender, EventArgs e)
{
if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox3.Text != "") && (textBox4.Text != "") &&
(textBox5.Text != ""))
{
StreamWriter sw;
FileInfo fi = new FileInfo("1.txt");
sw = fi.AppendText();
sw.WriteLine(textBox1.Text);
sw.WriteLine(textBox2.Text);
sw.WriteLine(textBox3.Text);
sw.WriteLine(textBox4.Text);
sw.WriteLine(textBox5.Text);
if (radioButton1.Checked = true)
{
sw.WriteLine("1");
}
else
if (radioButton2.Checked = true)
{
sw.WriteLine("2");
} else
if (radioButton3.Checked = true)
{
sw.WriteLine("3");
} else
if (radioButton4.Checked = true)
{
sw.WriteLine("4");
}
sw.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f3 = new Form2();
this.Hide();
f3.Show();
}
}
}
Form 5:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Артурка_6
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f3 = new Form2();
this.Hide();
f3.Show();
}
private void Form5_Load(object sender, EventArgs e)
{
string[] a = new string[1000];
int[] a1 = new int[1000];
int n = 0;
StreamReader streamReader = new StreamReader("res.txt");
string str = "";
while (!streamReader.EndOfStream)
{
if ((n % 2) == 0)
{
listBox1.Items.Add(streamReader.ReadLine());
}
else
{
listBox2.Items.Add(streamReader.ReadLine());
}
n++;
}
}
}
}
Form 6:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Артурка_6
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void Form6_Load(object sender, EventArgs e)
{
// Form2 f2 = new Form2();
// label1.Text="Кіл прав відп = "+f2.kil.ToString();
// label1.Text = f2.label2.Text;
// label2.Text = "Кіл всіх питань = " + f2.label3.Text;
// label3.Text = "Кіл набраних балів = " + (f2.kil*10).ToString();
//this.Hide();
// f2.Show();
label3.Text = label2.Text + "0";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
StreamWriter sw;
FileInfo fi = new FileInfo("res.txt");
sw = fi.AppendText();
sw.WriteLine(textBox1.Text);
sw.WriteLine(label3.Text);
sw.Close();
Form2 f6 = new Form2();
this.Hide();
f6.Show();
}
}
private void label6_Click(object sender, EventArgs e)
{
}
}
}
Висновок:Під час лабораторної роботи я створив систему для тестування учнів.