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;
using System.IO;

public partial class rl_admins_pg_ClassStudentsEdit : System.Web.UI.Page
{
    //**********************************
    SqlConnection con;
    SqlDataAdapter adp;
    DataSet ds;
    static int classId = 0;
    //**********************************
    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 = "دانشجویان کلاس";
                classId = Int32.Parse(Request.QueryString["classId"].ToString());
                SqlDataSource1.SelectCommand = "SELECT t_Students.studentId, t_Students.fullName, t_Students.gender, t_Students.tahsilat, t_Students.dateOfBirth, t_Students.melliCode, t_Students.studentPhotoUrl, t_Students.userName, t_Students.userCreater, t_ClassStudents.classId FROM t_Students INNER JOIN t_ClassStudents ON t_Students.studentId = t_ClassStudents.studentId Where t_ClassStudents.classId = " + classId;
                GridView1.DataBind();
            }
        }
        catch(Exception ex)
        {
        }
        finally
        {
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "SendMessage")
            {
                int studentId = Int32.Parse(e.CommandArgument.ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                SqlCommand cmd = con.CreateCommand();
                string userName = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Students", "userName", "studentId", studentId);
                Response.Redirect("pg_MessageSendNew.aspx?recieverRole=student&id=" + studentId + "&recieverUserName=" + userName + "&returnUrl=pg_ClassStudents.aspx?classId=" + classId);
            }
        }
        catch
        {
        }
    }

    protected string FindImageUrl(object StudentId)
    {
        string url = "~/photoes/";
        string conString = RamanConnectionString.LocalConnectionString();
        SqlConnection con = new SqlConnection(conString);
        SqlCommand cmd = con.CreateCommand();
        string picUrl = "";
        try
        {
            int studentId = Int32.Parse(StudentId.ToString());
            con.Open();
            cmd.CommandText = "select studentPhotoUrl from t_Students Where studentId = " + studentId;
            picUrl = (cmd.ExecuteScalar() != DBNull.Value ? cmd.ExecuteScalar().ToString() : "");
            string photoesFolderPath = Request.PhysicalApplicationPath + @"photoes\";
            if (!File.Exists(photoesFolderPath + picUrl))
            {
                picUrl = url + "noPersonalPhoto.gif";
            }
            else
            {
                picUrl = url + picUrl;
            }
        }
        catch
        {
            picUrl = "";
        }
        finally
        {
            if (con.State != ConnectionState.Closed)
                con.Close();
        }
        return picUrl;
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Redirect("pg_JoinedClasses.aspx");
        }
        catch
        {
        }
    }
}
