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_students_pg_TeachersProfileView : System.Web.UI.Page
{
    //***************************************************
    SqlConnection con;
    SqlCommand cmd;
    //***************************************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                string fullName = "", tahsilat = "", history = "";
                C_myClass.MenueItemsCreate(User, panelMenues);
                Label lblTitle = (Label)this.Master.FindControl("lblTitle");
                lblTitle.Text = "بیوگرافی مدرس";
                int teacherId = Int32.Parse(Request.QueryString["teacherId"].ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                cmd = con.CreateCommand();
                try
                {
                    con.Open();
                    cmd.CommandText = "select fullName, tahsilat, history from t_Teachers Where teacherId = " + teacherId;
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            fullName = (rdr.GetValue(0) != DBNull.Value ? rdr.GetString(0) : "");
                            tahsilat = (rdr.GetValue(1) != DBNull.Value ? rdr.GetString(1) : "");
                            history = (rdr.GetValue(2) != DBNull.Value ? rdr.GetString(2) : "");
                        }
                    }
                    rdr.Close();
                    lblFullName.Text = fullName;
                    lblTahsilat.Text = tahsilat;
                    lblHistory.Text = history;
                    imgTeacherPhoto.ImageUrl = FindTeacherImageUrl();
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
        finally
        {
        }
    }

    protected string FindTeacherImageUrl()
    {
        string url = "~/photoes/";
        string conString = RamanConnectionString.LocalConnectionString();
        SqlConnection con = new SqlConnection(conString);
        SqlCommand cmd = con.CreateCommand();
        string picUrl = "";
        try
        {
            int teacherId = Int32.Parse(Request.QueryString["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;
    }

    protected void btnBack_Click1(object sender, EventArgs e)
    {
        try
        {
            string returnUrl = Request.QueryString["returnUrl"].ToString();
            Response.Redirect(returnUrl);
        }
        catch
        {
        }
    }
}
