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_admins_pg_ExamsResaultSet : System.Web.UI.Page
{
    //*************************************
    static string lastQuery = "";
    SqlConnection con;
    SqlCommand cmd;
    //*************************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                C_myClass.MenueItemsCreate(User, panelMenues);
                Label lblTitle = (Label)this.Master.FindControl("lblTitle");
                lblTitle.Text = "آزمون های کلاسی";
                lastQuery = "SELECT t_Exams.examId, t_Exams.examName, t_Classes.classTitle, t_Teachers.fullName, t_Exams.examDate, t_Exams.examType FROM t_Classes INNER JOIN t_Exams ON t_Classes.classId = t_Exams.classId INNER JOIN t_Teachers ON t_Classes.teacherId = t_Teachers.teacherId";
            }
        }
        catch
        {
        }
        finally
        {
        }
    }

    protected void btnNewClass_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Redirect("pg_ExamAdd.aspx?returnUrl=pg_Exams.aspx");
        }
        catch
        {
        }
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            lastQuery = "SELECT t_Exams.examId, t_Exams.examName, t_Classes.classTitle, t_Teachers.fullName, t_Exams.examDate, t_Exams.examType FROM t_Classes INNER JOIN t_Exams ON t_Classes.classId = t_Exams.classId INNER JOIN t_Teachers ON t_Classes.teacherId = t_Teachers.teacherId WHERE t_Classes.status = N'جاری'";
            SqlDataSource1.SelectCommand = lastQuery;
            GridView1.DataBind();
        }
        catch
        {
        }
    }
    
    protected void btnAllShow_Click(object sender, EventArgs e)
    {
        try
        {
            lastQuery = "SELECT t_Exams.examId, t_Exams.examName, t_Classes.classTitle, t_Teachers.fullName, t_Exams.examDate, t_Exams.examType FROM t_Classes INNER JOIN t_Exams ON t_Classes.classId = t_Exams.classId INNER JOIN t_Teachers ON t_Classes.teacherId = t_Teachers.teacherId ";
            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("~/rl_teachers/pg_ExamResaultSet.aspx?examId=" + examId + "&returnUrl=~/rl_admins/pg_Exams.aspx");
            }
            else if (e.CommandName == "EditPress")
            {
                int examId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_ExamEdit.aspx?examId=" + examId + "&returnUrl=pg_Exams.aspx");
            }
            else if (e.CommandName == "DeletePress")
            {
                int examId = Int32.Parse(e.CommandArgument.ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                cmd = con.CreateCommand();
                try
                {
                    con.Open();
                    cmd.CommandText = "delete from t_Exams where examId = " + examId;
                    cmd.ExecuteNonQuery();
                    SqlDataSource1.SelectCommand = lastQuery;
                    GridView1.DataBind();
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
    }
}
