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_ClassSessions : System.Web.UI.Page
{
    //***********************************
    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 = "برنامه کلاسی";
                int classId = Int32.Parse(Request.QueryString["classId"].ToString());
                SqlDataSource1.SelectCommand = "SELECT t_ClassSessions.sessionId, t_Classes.classTitle, t_ClassSessions.sessionDate, t_ClassSessions.sessionTime, t_ClassSessions.classNumber FROM t_ClassSessions INNER JOIN t_Classes ON t_ClassSessions.classId = t_Classes.classId WHERE (t_ClassSessions.classId = " + classId + ")";
                GridView1.DataBind();
            }
        }
        catch
        {
        }
        finally
        {
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        try
        {
            string returnUrl = Request.QueryString["returnUrl"].ToString();
            Response.Redirect(returnUrl);
        }
        catch
        {
        }
    }
    protected void btnAddStudent_Click(object sender, EventArgs e)
    {
        try
        {
            int classId = Int32.Parse(Request.QueryString["classId"].ToString());
            Response.Redirect("pg_ClassSessionDefine.aspx?classId=" + classId + "&returnUrl=pg_ClassSessions.aspx");
        }
        catch
        {
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "DeletePress")
            {
                int sessionId = Int32.Parse(e.CommandArgument.ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                cmd = con.CreateCommand();
                try
                {
                    con.Open();
                    cmd.CommandText = "delete FROM t_ClassSessions Where sessionId = " + sessionId;
                    cmd.ExecuteNonQuery();
                    int classId = Int32.Parse(Request.QueryString["classId"].ToString());
                    SqlDataSource1.SelectCommand = "SELECT t_ClassSessions.sessionId, t_Classes.classTitle, t_ClassSessions.sessionDate, t_ClassSessions.sessionTime, t_ClassSessions.classNumber FROM t_ClassSessions INNER JOIN t_Classes ON t_ClassSessions.classId = t_Classes.classId WHERE (t_ClassSessions.classId = " + classId + ")";
                    GridView1.DataBind();
                }
                catch
                {
                }
                finally
                {
                    if (con.State != ConnectionState.Closed)
                        con.Close();
                }
            }
            else if (e.CommandName == "EditPress")
            {
                int classId = Int32.Parse(Request.QueryString["classId"].ToString());
                int sessionId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_ClassSessionEdit.aspx?sessionId=" + sessionId + "&classId=" + classId + "&returnUrl=pg_ClassSessions.aspx");
            }
        }
        catch
        {
        }
    }
}
