Sie sind auf Seite 1von 4

using using using using using using using

System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; System.Data.SqlClient;

namespace WindowsFormsApplication1 { public partial class Form4 : Form { int num = 60; int min; int hr; public Form4() { InitializeComponent(); } static int id; static int df; private void Form4_Load(object sender, EventArgs e) { label4.Text = "1"; label3.Text = "01"; label5.Text = "00"; if (int.Parse(label4.Text) > 0) { min = int.Parse(label4.Text); hr = int.Parse(label3.Text); timer1.Start(); } id = 1; SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=CHAUDHARY-PC\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand("Select QuestionNumber, Questions,A, B,C,D,MarkOfQuestion from questions where QuestionNumber=@qu",con); cmd.Parameters.AddWithValue("@qu",id); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { label7.Text = dr[0].ToString(); label1.Text = dr[1].ToString(); radioButton1.Text = dr[2].ToString(); radioButton2.Text = dr[3].ToString(); radioButton3.Text = dr[4].ToString(); radioButton4.Text = dr[5].ToString(); label13.Text = dr[6].ToString(); } } private void button1_Click(object sender, EventArgs e)

{ id++; SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=CHAUDHARY-PC\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand("Select QuestionNumber, Questions,A, B,C,D,MarkOfQuestion from questions where QuestionNumber=@qu", con); cmd.Parameters.AddWithValue("@qu", id); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { label7.Text = dr[0].ToString(); label1.Text = dr[1].ToString(); radioButton1.Text = dr[2].ToString(); radioButton2.Text = dr[3].ToString(); radioButton3.Text = dr[4].ToString(); radioButton4.Text = dr[5].ToString(); label13.Text = dr[6].ToString(); } } private void button2_Click(object sender, EventArgs e) { if (label1.Text.Length == 1) { button2.Enabled = false; } id--; SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=CHAUDHARY-PC\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand("Select QuestionNumber, Questions,A, B,C,D,MarkOfQuestion from questions where QuestionNumber=@qu", con); cmd.Parameters.AddWithValue("@qu", id); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { label7.Text = dr[0].ToString(); label1.Text = dr[1].ToString(); radioButton1.Text = dr[2].ToString(); radioButton2.Text = dr[3].ToString(); radioButton3.Text = dr[4].ToString(); radioButton4.Text = dr[5].ToString(); label13.Text = dr[6].ToString(); } } private void timer1_Tick(object sender, EventArgs e) { if (num >= 0) { label5.Text = num.ToString(); num--; if (num == 0)

{ min--; label4.Text = min.ToString(); } else { } bool b = true; if (min == 0 && b==true) { hr--; label3.Text = hr.ToString(); min = 40; label4.Text = min.ToString(); num = 60; } if (min == 0 && hr == 0 && num == 0) { //timer1.Stop(); label4.Enabled = false; label5.Enabled = false; MessageBox.Show("Time over"); button1.Enabled = false; button2.Enabled = false; label1.Visible = false; radioButton1.Hide(); radioButton2.Hide(); radioButton3.Hide(); radioButton4.Hide(); label4.Enabled = true; //label5.Text = "00"; } else if(label4.Text.Length==0) { timer1.Stop(); } } } private void label3_Click(object sender, EventArgs e) { } bool a; private void timer2_Tick(object sender, EventArgs e) { if (a == true) { label9.ForeColor = Color.Green; a = false; } else { label9.ForeColor = Color.Blue; a = true;

} } private void groupBox2_Enter(object sender, EventArgs e) { } string file; private void button3_Click(object sender, EventArgs e) { OpenFileDialog fg = new OpenFileDialog(); if (fg.ShowDialog() == DialogResult.OK) file = fg.FileName; pictureBox1.ImageLocation = file; } } }

Das könnte Ihnen auch gefallen