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;

public partial class rl_students_pg_Exams : System.Web.UI.Page
{
    //**********************************
    static string lastQuery = "";
    //**********************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                if (User.IsInRole("student"))
                {
                    C_myClass.MenueItemsCreate(User, panelMenues);
                    Label lblTitle = (Label)this.Master.FindControl("lblTitle");
                    lblTitle.Text = "آزمون های کلاسی";
                    int studentId = Int32.Parse(Session["iden"].ToString());
                    lastQuery = "SELECT t_Classes.classTitle, t_Teachers.fullName, t_Exams.* FROM t_Teachers INNER JOIN t_Classes ON t_Teachers.teacherId = t_Classes.teacherId INNER JOIN t_Exams INNER JOIN t_ClassStudents ON t_Exams.classId = t_ClassStudents.classId ON t_Classes.classId = t_ClassStudents.classId WHERE (t_ClassStudents.studentId = " + studentId + ")";
                    SqlDataSource1.SelectCommand = lastQuery;
                    GridView1.DataBind();
                }
            }
        }
        catch
        {
        }
    }
    protected void btnAllShow_Click(object sender, EventArgs e)
    {
        try
        {
            int studentId = Int32.Parse(Session["iden"].ToString());
            lastQuery = "SELECT t_Classes.classTitle, t_Teachers.fullName, t_Exams.* FROM t_Teachers INNER JOIN t_Classes ON t_Teachers.teacherId = t_Classes.teacherId INNER JOIN t_Exams INNER JOIN t_ClassStudents ON t_Exams.classId = t_ClassStudents.classId ON t_Classes.classId = t_ClassStudents.classId WHERE (t_ClassStudents.studentId = " + studentId + ")";
            SqlDataSource1.SelectCommand = lastQuery;
            GridView1.DataBind();
        }
        catch
        {
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            int studentId = Int32.Parse(Session["iden"].ToString());
            lastQuery = "SELECT t_Classes.classTitle, t_Teachers.fullName, t_Exams.* FROM t_Teachers INNER JOIN t_Classes ON t_Teachers.teacherId = t_Classes.teacherId INNER JOIN t_Exams INNER JOIN t_ClassStudents ON t_Exams.classId = t_ClassStudents.classId ON t_Classes.classId = t_ClassStudents.classId WHERE (t_ClassStudents.studentId = " + studentId + ") AND (t_Classes.status = N'جاری')";
            SqlDataSource1.SelectCommand = lastQuery;
            GridView1.DataBind();
        }
        catch
        {
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "ResaultPress")
            {
                int examId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_ExamResaultView.aspx?examId=" + examId + "&returnUrl=pg_Exams.aspx");
            }
        }
        catch
        {
        }
    }
}
