using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq; using nmsLogin; using System.Collections.Generic; using nmsSetup; using System.Data.SqlClient; public partial class adminblock_changeStudentAns : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString); static string id = "", CheckedValue = "", lable = ""; protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { ViewState["Pageindex"] = "1"; ViewState["perpagequestion"] = "20"; InsertInRadio(1); } } private void InsertInRadio(Int32 pageIndex) { //DataTable dt = new DataTable(); //dt = table(); //string str = ViewState["paperid"].ToString(); //string sts = ViewState["perpagequestion"].ToString(); SqlDataAdapter adp = new SqlDataAdapter("viewTestfinal", con); adp.SelectCommand.CommandType = CommandType.StoredProcedure; if (Request.QueryString["id"] != null) adp.SelectCommand.Parameters.AddWithValue("@paperid", Request.QueryString["id"].ToString()); //if (Request.QueryString["id"] != null) adp.SelectCommand.Parameters.AddWithValue("@pageSize", "20"); if (Request.QueryString["unid"] != null) adp.SelectCommand.Parameters.AddWithValue("@studentid", Request.QueryString["unid"].ToString()); adp.SelectCommand.Parameters.AddWithValue("@pageIndex", pageIndex.ToString()); //cmd.Parameters.AddWithValue("@testid", 13); //DataRow row; DataSet ds = new DataSet(); adp.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { Session["NoOfRecord"] = ds.Tables[1].Rows[0][0].ToString(); //{ // InsertInRadio(Convert.ToInt32(ViewState["Pageindex"].ToString())); // dt = (DataTable)Session["TableRecord"]; //} Int32 noOfRecord = Convert.ToInt32(Session["NoOfRecord"].ToString()); lblCurrentPage.Text = ViewState["Pageindex"].ToString(); //if (ViewState["paperid"] != null) if ((noOfRecord % Convert.ToInt32(ViewState["perpagequestion"].ToString())) == 0) lblLastPage.Text = Convert.ToInt32(noOfRecord / Convert.ToInt32(ViewState["perpagequestion"].ToString())).ToString(); else lblLastPage.Text = Convert.ToInt32(noOfRecord / Convert.ToInt32(ViewState["perpagequestion"].ToString()) + 1).ToString(); //lnkfstPage.Enabled = true; //lnkLastpage.Enabled = true; btnnext.Enabled = true; btnprev.Enabled = true; if (Convert.ToInt32(ViewState["Pageindex"].ToString()) == 1) { //lnkfstPage.Enabled = false; btnprev.Enabled = false; } if (Convert.ToInt32(ViewState["Pageindex"].ToString()) == Convert.ToInt32(lblLastPage.Text)) { //lnkLastpage.Enabled = false; btnnext.Enabled = false; } Repeater2.DataSource = ds.Tables[0]; Repeater2.DataBind(); } //Ques.Text = dt.Rows[Convert.ToInt32(Label1.Text)][1].ToString(); //lblqno.Text = dt.Rows[Convert.ToInt16(Label1.Text)][0].ToString(); //if (Convert.ToInt32(lblqno.Text) > 1) { btnprev.Visible = true; } //else btnprev.Visible = false; //if (Convert.ToInt32(lblqno.Text) == 5) { btnnext.Visible = false; } //else btnnext.Visible = true; //for (int a = 2; a <= 5; a++) //{ // rboptions.Items.Add(dt.Rows[Convert.ToInt32(Label1.Text)][a].ToString()); //} // Repeater1.DataSource = dt; //Repeater1.DataBind(); //Session["NoOfRecord"] = ds.Tables[1].Rows[0][0].ToString(); //if (ds.Tables[0].Rows.Count > 0) //{ // for (Int16 a = 0; a < ds.Tables[0].Rows.Count; a++) // { // row = dt.NewRow(); // row["QNo"] = a + 1; // row["Question"] = ds.Tables[0].Rows[a][2].ToString(); // row["Op1"] = ds.Tables[0].Rows[a][3].ToString(); // row["Op2"] = ds.Tables[0].Rows[a][4].ToString(); // row["Op3"] = ds.Tables[0].Rows[a][5].ToString(); // row["Op4"] = ds.Tables[0].Rows[a][6].ToString(); // row["Answer"] = ds.Tables[0].Rows[a][7].ToString(); // row["perQuesMark"] = ds.Tables[0].Rows[a][10].ToString(); // row["Marked"] = ""; // row["Incomplete"] = ""; // row["Completed"] = " "; // row["Sans"] = "x"; // dt.Rows.Add(row); // } //} //Session["TableRecord"] = dt; } private void InsertAns() { Int32 question; string st = ""; //question = Repeater1.FindControl(""); foreach (RepeaterItem a in Repeater2.Items) { CheckedValue = "0"; if (((RadioButton)a.FindControl("A")).Checked) { CheckedValue = "A"; } else if (((RadioButton)a.FindControl("B")).Checked) { CheckedValue = "B"; } else if (((RadioButton)a.FindControl("C")).Checked) { CheckedValue = "C"; } else if (((RadioButton)a.FindControl("D")).Checked) { CheckedValue = "D"; } //else if (CheckedValue == "0") //{ // NotFill = NotFill + 1; //} if (CheckedValue != "0") { st += " if not exists (select *from tblstudentAns where Questionid=" + ((Label)(a.FindControl("Label1"))).Text + " and Studentid=" + Request.QueryString["unid"].ToString() + " and PaperDetailid=" + Request.QueryString["id"].ToString() + ")"; st += " begin insert into tblstudentAns (Questionid,QuestionAns,Studentid,PaperDetailid,QModule)values(" + ((Label)(a.FindControl("Label1"))).Text + ",'" + CheckedValue + "'," + Request.QueryString["unid"].ToString() + "," + Request.QueryString["id"].ToString() + "," + ((Label)(a.FindControl("lblLevel"))).Text + ");"; st += " end else begin "; st += " update tblstudentAns set QuestionAns='" + CheckedValue + "' where Questionid=" + ((Label)(a.FindControl("Label1"))).Text + " and Studentid=" + Request.QueryString["unid"].ToString() + " and PaperDetailid=" + Request.QueryString["id"].ToString() + "; end "; } } if (con.State == ConnectionState.Closed) con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "spinsStudentAnswer"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@query", st); // cmd.Parameters.AddWithValue("@id", ((Label)(a.FindControl("Label1"))).Text); cmd.Connection = con; cmd.ExecuteScalar().ToString(); con.Close(); cmd.Dispose(); //lblWrite.Text = "Write Ans are = " + " " + WriteAns; //lblWrong.Text = "Wrong Ans are =" + " " + WrongAns; //lblBlank.Text = "Blank are =" + " " + NotFill; } protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (((Label)(e.Item.FindControl("lblselAns"))).Text != "") { if (((Label)(e.Item.FindControl("lblselAns"))).Text == "A") { // CheckedValue = "A"; ((RadioButton)e.Item.FindControl("A")).Checked = true; } if (((Label)(e.Item.FindControl("lblselAns"))).Text == "B") { ((RadioButton)e.Item.FindControl("B")).Checked = true; } if (((Label)(e.Item.FindControl("lblselAns"))).Text == "C") { ((RadioButton)e.Item.FindControl("C")).Checked = true; } if (((Label)(e.Item.FindControl("lblselAns"))).Text == "D") { ((RadioButton)e.Item.FindControl("D")).Checked = true; } } } protected void Button1_Click(object sender, EventArgs e) { try { InsertAns(); lblmesage.Text = "Succssfully Changed !"; } catch (Exception ex) { } } protected void btnnext_Click(object sender, EventArgs e) { //Label1.Text = (Convert.ToInt32(Label1.Text) + 1).ToString(); //rboptions.Items.Clear(); ViewState["Pageindex"] = (Convert.ToInt32(lblCurrentPage.Text) + 1); //mark_unmark(); InsertAns(); InsertInRadio(Convert.ToInt32(ViewState["Pageindex"].ToString())); //showvaule(); // selected_index(); } protected void btnprev_Click(object sender, EventArgs e) { //Label1.Text = (Convert.ToInt32(Label1.Text) - 1).ToString(); // rboptions.Items.Clear(); //InsertInRadio(Convert.ToInt32(lblCurrentPage.Text) - 1); ViewState["Pageindex"] = (Convert.ToInt32(lblCurrentPage.Text) - 1).ToString(); // mark_unmark(); InsertAns(); InsertInRadio(Convert.ToInt32(ViewState["Pageindex"].ToString())); // showvaule(); //selected_index(); } }