在线试卷 [英] Online question paper

查看:65
本文介绍了在线试卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算每个问题的标记,但是当增量发生时,它会一次又一次地加载第一个问题,如果我将变量设为2,它将永远不会进入计算标记的位置。如果ii重复问题1然后我们需要回答下一个问题,因为它再次加载问题1



我尝试了什么:



im trying to calculate marks of every ques but as and when the increment happens it loads the first question again and again and if i give the variable as 2 it will never enter the place where marks are calculated . if ii repeats with question 1 then we need to ans for next ques with previous question as it is loading again question 1

What I have tried:

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;
using System.Data.SqlClient;



namespace trial__
{
    public partial class Form1 : Form
    {
        public int incre = 1;
        public int b;
        public string y;
        public string z;
        public int marks;

        public Form1()
        {
            InitializeComponent();
            radioButton1.TabStop = false;
            radioButton2.TabStop = false;
            radioButton3.TabStop = false;
            radioButton4.TabStop = false;
           
            marks = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //
            String Source = "xxxx";            
            SqlConnection con_2 = new SqlConnection(Source);
            {
                con_2.Open();
                MessageBox.Show("connected to db");
                string a = incre.ToString();
                string sqlSelectQuery = @"SELECT *FROM [Table]";
                SqlCommand cmd = new SqlCommand(sqlSelectQuery, con_2);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    label1.Text = (dr["ques"].ToString());
                    textBox1.Text = (dr["sl"].ToString());
                    radioButton1.Text = (dr["op A"].ToString());
                    radioButton2.Text = (dr["op B"].ToString());
                    radioButton3.Text = (dr["op C"].ToString());
                    radioButton4.Text = (dr["op D"].ToString());
                    
                  
                }
            }
            con_2.Close();
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string a = incre.ToString();
            String Source ="xxxx";
            SqlConnection con_2 = new SqlConnection(Source);
            {
                con_2.Open();
              
                string sqlSelectQuery = @"SELECT *FROM [Table] WHERE sL=" + a;
                SqlCommand cmd = new SqlCommand(sqlSelectQuery, con_2);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    label1.Text = (dr["ques"].ToString());
                    textBox1.Text = (dr["sl"].ToString());
                    radioButton1.Text = (dr["op A"].ToString());
                    radioButton2.Text = (dr["op B"].ToString());
                    radioButton3.Text = (dr["op C"].ToString());
                    radioButton4.Text = (dr["op D"].ToString());


                    if (radioButton1.Checked == true)
                    {
                        y = dr["ans"].ToString();
                        z = dr["marks"].ToString();
                        int bi = Convert.ToInt32(z);
                        
                        //ans.Text = "meg";
                        if (radioButton1.Text == y)
                        {

                            marks = marks +bi;
                        }


                    }
                    if (radioButton2.Checked == true)
                    {
                        string g = (dr["ans"].ToString());
                        string h = dr["marks"].ToString();
                        int bd = Convert.ToInt32(h);
                        

                        if (radioButton2.Text == g)

                        {
                            marks = marks + bd;
                        }


                    }

                    if (radioButton3.Checked == true)
                    {
                        string g = (dr["ans"].ToString());
                        string h = dr["marks"].ToString();
                        int bk = Convert.ToInt32(h);


                        if (radioButton3.Text == g)

                        {
                            marks = marks + bk;
                        }


                    }

                    if (radioButton4.Checked == true)
                    {
                        string g = (dr["ans"].ToString());
                        string h = dr["marks"].ToString();
                        int bl = Convert.ToInt32(h);


                        if (radioButton4.Text == g)

                        {
                            marks = marks + bl;
                        }


                    }


                }

            }
            
            con_2.Close();
            incre++;
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            radioButton3.Checked = false;
            radioButton4.Checked = false;

推荐答案

没有你的数据库我们无法运行你的代码,这正是这里所需要的 - 如果不运行代码并查看变量,你就无法解决出错的问题。所以,这取决于你。

幸运的是,你有一个工具可以帮助你找到正在发生的事情:调试器。你如何使用它取决于你的编译器系统,但是一个快速的谷歌用于你的IDE名称和调试器应该给你你需要的信息。



放一个断点在函数的第一行,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一种新的(非常非常有用的)技能:调试!



但......你的检查标记代码相当奇怪。您似乎从数据库中读取当前问题,并设置标签文本以匹配它,然后立即根据用户的最后一组响应进行标记。

您可能最好将其拆分为两个单独的方法:一个用于标记当前问题,另一个用于加载特定问题。从你的Load事件处理程序中调用第二个来设置所有内容,然后在你的按钮Click事件中,首先调用eth来标记它,然后第二个调用以加载一个新问题。它只是让它更清晰,更容易维护,甚至发展!
Without your database we can't run your code, and that's exactly what is needed here - you can't workout what is going wrong without running the code and looking at variables as it goes. So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

But ... your "check the marks" code is rather odd. You appear to read the current question from the db, and set the label texts to match it, then immediately mark it based on the users last set of responses.
You would probably be better off splitting this into two separate methods: one to mark the current question, then a second to load a specific question. Call the second from your Load event handler to set everything up, then in your button Click event, call eth first to mark it, then the second to load a new question. It just makes it clearer what is going on, and easier to maintain and even develop!


这篇关于在线试卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆