Я создаю приложение викторины с использованием c#. как написать код, чтобы получить секретный вопрос
я создал приложение викторины, я хочу добавить кнопку privious, чтобы получить вопрос.
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Configuration; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class ExamHome : Form { int timeleft; int seconds; int q = 1; public ExamHome() { InitializeComponent(); } SqlConnection con = new SqlConnection("uid=sa;password=1234;server=anjibabu;database=examportal"); private void button1_Click(object sender, EventArgs e) { if (comboBox1.Text == "Daily Test") { timeleft = 20; seconds = 60; label5.Text = "20 MINUTES"; } else if (comboBox1.Text == "Grand Test") { timeleft = 40; seconds = 60; label5.Text = "40 MINUTES"; } if (comboBox1.Text == "") { MessageBox.Show("Please Select Exam Type!"); } else if (comboBox2.Text == "") { MessageBox.Show("Please Select Subject!"); } else { timer1.Start(); label1.Visible = false; label2.Visible = false; panel1.Visible = true; button2.Visible = true; button1.Visible = false; groupBox1.Visible = true; comboBox1.Visible = false; comboBox2.Visible = false; SqlCommand cmd1 = new SqlCommand("SELECT MAX(slNO) FROM MQ2 WHERE Subject='" +comboBox2 .SelectedItem + "'", con); SqlCommand cmd2 = new SqlCommand("SELECT MIN(slNO) FROM MQ2 WHERE Subject='" +comboBox2 .SelectedItem + "'", con); con.Open(); int count = (int)cmd1.ExecuteScalar(); int sc = (int)cmd2.ExecuteScalar(); Random rnd = new Random(); int i = rnd.Next(sc, count);//Here specify your starting slno of question table and ending no. getQuestion(i); } } private void ExamHome_Load(object sender, EventArgs e) { panel1.Visible = false; button2.Visible = false; groupBox1.Visible = false; } private void button2_Click(object sender, EventArgs e) { q++; getNextQuestion(); } public void getQuestion(int no) { string str = "select * from MQ2 where slNo=" + no + " "; SqlDataAdapter da2 = new SqlDataAdapter(str, con); DataSet ds2 = new DataSet(); da2.Fill(ds2, "MQ2"); if (ds2.Tables[0].Rows.Count > 0) { DataRow dtr; int i = 0; while (i < ds2.Tables[0].Rows.Count) { dtr = ds2.Tables[0].Rows[i]; label3.Text = "Q." + q.ToString(); label4.Text = dtr["Question"].ToString(); radioButton1.Text = dtr["Option1"].ToString(); radioButton2.Text = dtr["Option2"].ToString(); radioButton3.Text = dtr["Option3"].ToString(); radioButton4.Text = dtr["Option4"].ToString(); i++; } } } public void getNextQuestion() { if (comboBox1.Text == "Daily Test") { SqlCommand cmd2 = new SqlCommand("SELECT MAX(slNO) FROM MQ2 WHERE Subject='" + comboBox2.SelectedItem + "'", con); SqlCommand cmd1 = new SqlCommand("SELECT MIN(slNO) FROM MQ2 WHERE Subject='" + comboBox2.SelectedItem + "'", con); int sc = (int)cmd1.ExecuteScalar(); int count = (int)cmd2.ExecuteScalar(); if (q <= 10) { Random rnd = new Random(); int i = rnd.Next(sc, count); getQuestion(i); if (q == 10) { button2.Text = "Finish"; } } else { timer1.Stop(); this.Hide(); Home h = new Home(); h.Visible = true; } } else if (comboBox1.Text == "Grand Test") { SqlCommand cmd2 = new SqlCommand("SELECT MAX(slNO) FROM MQ2 WHERE Subject='" + comboBox2.SelectedItem + "'", con); SqlCommand cmd1 = new SqlCommand("SELECT MIN(slNO) FROM MQ2 WHERE Subject='" + comboBox2.SelectedItem + "'", con); int sc = (int)cmd1.ExecuteScalar(); int count = (int)cmd2.ExecuteScalar(); if (q <= 20) { Random rnd = new Random(); int i = rnd.Next(sc, count); getQuestion(i); if (q == 20) { button2.Text = "Finish"; } } else { timer1.Stop(); this.Hide(); Home h = new Home(); h.Visible = true; } } } private void timer1_Tick(object sender, EventArgs e) { if (timeleft > 0) { timeleft = timeleft - 1; label5.Text = timeleft + "" + "MINUTES"; } else { timer1.Stop(); MessageBox.Show("Time Up!"); this.Hide(); Home h = new Home(); h.Show(); } } private void timer2_Tick(object sender, EventArgs e) { if (seconds > 0) { seconds = seconds - 1; label5.Text = timeleft + "::" + seconds; } } } }
Richard MacCutchan
Где и в чем проблема?
[no name]
Когда вы попросили учителя помочь вам с домашним заданием, что он вам сказал?