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