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_TeachersList : 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 == "EditPress")
            {
                int teacherId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_EditTeacher.aspx?teacherId=" + teacherId.ToString() + "&returnUrl=pg_TeachersList.aspx");
            }
            else if (e.CommandName == "DeletePress")
            {
                try
                {
                    string conString = RamanConnectionString.LocalConnectionString();
                    con = new SqlConnection(conString);
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    int teacherId = Int32.Parse(e.CommandArgument.ToString());
                    string userName = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Teachers", "userName", "teacherId", teacherId);
                    cmd.CommandText = "delete from t_Teachers Where teacherId = " + teacherId;
                    cmd.ExecuteNonQuery();
                    Membership.DeleteUser(userName, true);
                    GridView1.DataBind();
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
    }
    protected string FindImageUrl(object TeacherId)
    {
        string url = "~/photoes/";
        string conString = RamanConnectionString.LocalConnectionString();
        SqlConnection con = new SqlConnection(conString);
        SqlCommand cmd = con.CreateCommand();
        string picUrl = "";
        try
        {
            int teacherId = Int32.Parse(TeacherId.ToString());
            con.Open();
            cmd.CommandText = "select teacherPhotoUrl from t_Teachers Where teacherId = " + teacherId;
            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;
    }
}
