예제 #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        nsquiz.clstbqst    obj    = new nsquiz.clstbqst();
        nsquiz.clstbqstprp objprp = new nsquiz.clstbqstprp();
        objprp.qstcatcod = Convert.ToInt32(DropDownList1.SelectedValue);
        objprp.qstlvl    = DropDownList2.SelectedValue;
        objprp.qstdsc    = TextBox1.Text;
        // obj.save_rec(objprp);
        Int32 a = obj.save_rec(objprp);

        //code for answer
        nsquiz.clsopt    obj1    = new nsquiz.clsopt();
        nsquiz.clsoptprp objprp1 = new nsquiz.clsoptprp();
        objprp1.optqstcode = a;
        objprp1.optdsc     = TextBox2.Text;
        obj1.save_rec(objprp1);
        Response.Redirect("frmqst.aspx");
    }
예제 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Page.IsPostBack == false)
     {
         if (Session["ccod"] == null)
         {
             Response.Redirect("index.aspx");
         }
         else
         {
             nsquiz.clstbqst           obj = new nsquiz.clstbqst();
             List <nsquiz.clstbqstprp> k   = obj.disp_rec(Convert.ToInt32(Session["ccod"]), Session["lvl"].ToString());
             DataTable tb = new DataTable();
             tb.Columns.Add(new DataColumn("qstcode", Type.GetType("System.Int32")));
             tb.Columns.Add(new DataColumn("qstdsc", Type.GetType("System.String")));
             //tb.Columns.Add(new DataColumn("optcod", Type.GetType("System.ToInt32")));
             List <String> arr = new List <String>();
             for (int i = 0; i < 6; i++)
             {
                 Random rnd  = new Random();
                 int    idx  = rnd.Next(0, k.Count);
                 int    flag = 0;
                 for (int t = 0; t < tb.Rows.Count; t++)
                 {
                     if (Convert.ToInt32(tb.Rows[t]["qstcode"]) == Convert.ToInt32(k[idx].qstcode))
                     {
                         flag = 1;
                         break;
                     }
                 }
                 if (flag == 1)
                 {
                     i--;
                     continue;
                 }
                 DataRow r = tb.NewRow();
                 r[0] = k[idx].qstcode;
                 r[1] = k[idx].qstdsc;
                 //add option
                 // List<String> arr = new List<string>();
                 nsquiz.clsopt           obj1 = new nsquiz.clsopt();
                 List <nsquiz.clsoptprp> kt   = obj1.find_rec(k[idx].qstcode);
                 arr.Add(kt[0].optdsc);
                 tb.Rows.Add(r);
             }
             //display paper to user
             for (int j = 0; j < arr.Count; j++)
             {
                 String temp        = arr[j];
                 Random a           = new Random();
                 int    RandomIndex = a.Next(j, arr.Count);
                 arr[j]           = arr[RandomIndex];
                 arr[RandomIndex] = temp;
             }
             ViewState["ppr"]     = tb;
             ViewState["ans"]     = arr;
             GridView1.DataSource = tb;
             GridView1.DataBind();
             DataList1.DataSource = arr;
             DataList1.DataBind();
         }
     }
 }