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.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class rl_students_pg_ExamResaultView : System.Web.UI.Page
{
    //*********************************
    SqlConnection con;
    SqlCommand cmd;
    //*********************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                string examName = "", examDate = "", examType = "", questionsType = "", status = "", present = "";
                int grade = 0, maxGrade = 0;
                bool presentBool = false;
                C_myClass.MenueItemsCreate(User, panelMenues);
                Label lblTitle = (Label)this.Master.FindControl("lblTitle");
                lblTitle.Text = "نتیجه آزمون";
                int examId = Int32.Parse(Request.QueryString["examId"].ToString());
                int studentId = Int32.Parse(Session["iden"].ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                cmd = con.CreateCommand();
                try
                {
                    con.Open();
                    cmd.CommandText = "select examName, examDate, examType, questionsType, maxGrade from t_Exams WHERE examId = " + examId;
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            examName = (rdr.GetValue(0) != DBNull.Value ? rdr.GetString(0) : "");
                            examDate = (rdr.GetValue(1) != DBNull.Value ? rdr.GetString(1) : "");
                            examType = (rdr.GetValue(2) != DBNull.Value ? rdr.GetString(2) : "");
                            questionsType = (rdr.GetValue(3) != DBNull.Value ? rdr.GetString(3) : "");
                            maxGrade = (rdr.GetValue(4) != DBNull.Value ? rdr.GetInt32(4) : -1);
                        }
                    }
                    rdr.Close();
                    cmd.CommandText = "select grade, status, present from t_ExamResaults Where examId = " + examId + " AND studentId = " + studentId;
                    SqlDataReader rdr2 = cmd.ExecuteReader();
                    if (rdr2.HasRows)
                    {
                        while (rdr2.Read())
                        {
                            grade = (rdr2.GetValue(0) != DBNull.Value ? rdr2.GetInt32(0) : -1);
                            status = (rdr2.GetValue(1) != DBNull.Value ? rdr2.GetString(1) : "");
                            presentBool = (rdr2.GetValue(2) != DBNull.Value ? rdr2.GetBoolean(2) : false);
                        }
                        present = ( presentBool ? "حاضر" : "غایب");
                    }
                    else
                    {
                        status = "اعلام نشده";
                        present = "اعلام نشده";
                        grade = -1;
                    }
                    rdr2.Close();
                    ////////////////////////////
                    lblExamName.Text = examName;
                    lblExamDate.Text = examDate;
                    lblExamType.Text = examType;
                    lblQuestionsType.Text = questionsType;
                    lblGrade.Text = grade.ToString() + " از " + maxGrade.ToString();
                    lblStatus.Text = status;
                    lblPresent.Text = present;
                }
                catch(Exception ex)
                {
                    //lblExamDate.Text = ex.Message;
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
        finally
        {
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        try
        {
            string returnUrl = Request.QueryString["returnUrl"].ToString();
            Response.Redirect(returnUrl);
        }
        catch
        {
        }
    }
}
