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

public partial class rl_admins_pg_AllUsersList : System.Web.UI.Page
{
    //**********************************
    SqlConnection con;
    //**********************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            C_myClass.MenueItemsCreate(User, panelMenues);
            Label lblTitle = (Label)this.Master.FindControl("lblTitle");
            lblTitle.Text = "لیست دانشجویان";
        }
        catch
        {
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "DeletePress")
            {
                try
                {
                    string conString = RamanConnectionString.LocalConnectionString();
                    con = new SqlConnection(conString);
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    int studentId = Int32.Parse(e.CommandArgument.ToString());
                    string userName = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Students", "userName", "studentId", studentId);
                    cmd.CommandText = "delete from t_Students Where studentId = " + studentId;
                    cmd.ExecuteNonQuery();
                    Membership.DeleteUser(userName, true);
                    GridView1.DataBind();
                }
                catch (Exception exc)
                {
                }
                finally
                {
                    con.Close();
                }
            }
            else if (e.CommandName == "EditPress")
            {
                int studentId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_EditStudent.aspx?studentId=" + studentId.ToString() + "&returnUrl=pg_StudentsList.aspx");
            }
        }
        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().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 GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
        }
        catch
        {
        }
    }
}
